This section covers advanced or less common features of the Flashnet AMM SDK that can be useful in specific scenarios.

Clawback

The clawback function is a recovery mechanism for users who have sent funds to an AMM pool for an operation (like a swap or liquidity addition) that never completed. If a user’s inbound transfer gets “stuck,” this function allows them to request a refund from the AMM validators.

When to Use Clawback

You should only use the clawback function after an operation has failed and you have a sparkTransferId for a transfer that was sent to an LP wallet but was not processed. This is an exceptional recovery tool and should not be part of a normal application flow.

How it Works

The user signs an intent asserting ownership of the stuck transfer. The AMM validators verify that the transfer was indeed never used in a successful operation and then refund the assets to the original sender.

Implementation

async function requestClawback(stuckTransferId: string, poolId: string) {
  try {
    const response = await client.clawback({
      sparkTransferId: stuckTransferId,
      lpIdentityPublicKey: poolId,
    });

    if (response.accepted) {
      console.log('Clawback request accepted.');
      console.log('Track status with internalRequestId:', response.internalRequestId);
    } else {
      console.error('Clawback request rejected:', response.error);
    }

  } catch (error) {
    console.error('Failed to request clawback:', error);
  }
}
To use this function, you need:
  • The sparkTransferId of the original, stuck transfer.
  • The lpIdentityPublicKey (the pool ID) to which the funds were sent.
The wallet used to initialize the client must be the one that originally sent the funds.