Usage
Example of signing a quote (creating a commitment).
Example of how to create response for quote for market makers using TypeScript
Here params has same type as what you receive from relay in "quote" event
params: {
defuse_asset_identifier_in: string;
defuse_asset_identifier_out: string;
exact_amount_in: string | undefined;
exact_amount_out: string | undefined;
min_deadline_ms: number;
},You can read more about versioned nonces here
import {VersionedNonceBuilder} from "@defuse-protocol/intents-sdk";
const generateNonce = async (deadline: Date): Promise<string> => {
const account = await getAccount(); //function that will return Account instance(from "near-api-js") of market makers' Near account
const salt_hex = await account.viewFunction({
contractId: "intents.near",
methodName: "current_salt",
});
let salt_bytes = Uint8Array.from(Buffer.from(salt_hex, "hex"));
let versionedNonce = VersionedNonceBuilder.encodeNonce(salt_bytes, deadline);
if (await isNonceUsed(versionedNonce)) {
// this step can be skipped, but if the nonce is already used the quote won't be taken into account
return generateNonce(deadline);
} else {
return versionedNonce;
}
}
const isNonceUsed = async (nonce: string) => {
const account = await getAccount();
return await account.viewFunction({
contractId: defuseContract,
methodName: 'is_nonce_used',
args: {
account_id: account.accountId,
nonce,
},
});
}Last updated