Skip to content

Commit

Permalink
Merge pull request #91 from tinymanorg/feat/extra-app-call-note
Browse files Browse the repository at this point in the history
Include extra app call note data if added to the params
  • Loading branch information
gulcinuras authored Aug 30, 2024
2 parents 9d83dd5 + 5e1fd04 commit b22e80e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare class TinymanJSSDKConfig {
/**
* @returns {Uint8Array} - encoded note includings version with client name
*/
getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue): Uint8Array;
getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue, extraData?: Record<string, string>): Uint8Array;
}
export declare const tinymanJSSDKConfig: TinymanJSSDKConfig;
export {};
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/swap/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface GenerateSwapTxnsParams {
swapType: SwapType;
slippage: number;
initiatorAddr: string;
appCallNoteExtraData?: Record<string, string>;
}
export type GenerateV1_1SwapTxnsParams = Omit<GenerateSwapTxnsParams, "quote" | "network"> & {
quoteAndPool: DirectSwapQuoteAndPool;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tinymanorg/tinyman-js-sdk",
"version": "4.0.4",
"version": "4.0.5",
"description": "Tinyman JS SDK",
"author": "Tinyman Core Team",
"license": "MIT",
Expand Down
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class TinymanJSSDKConfig {
/**
* @returns {Uint8Array} - encoded note includings version with client name
*/
getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue): Uint8Array {
getAppCallTxnNoteWithClientName(
contractVersion: ContractVersionValue,
extraData?: Record<string, string>
): Uint8Array {
const versionMarker =
contractVersion === CONTRACT_VERSION.V1_1 ? "v1" : contractVersion;
const data = JSON.stringify({origin: this.clientName, ...extraData});

return encodeString(`tinyman/${versionMarker}:j{"origin":"${this.clientName}"}`);
return encodeString(`tinyman/${versionMarker}:j${data}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface GenerateSwapTxnsParams {
swapType: SwapType;
slippage: number;
initiatorAddr: string;
appCallNoteExtraData?: Record<string, string>;
}

export type GenerateV1_1SwapTxnsParams = Omit<
Expand Down
5 changes: 4 additions & 1 deletion src/swap/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ async function generateTxns(
V2_SWAP_APP_CALL_SWAP_TYPE_ARGS_ENCODED[swapType],
algosdk.encodeUint64(assetOutAmount)
],
note: tinymanJSSDKConfig.getAppCallTxnNoteWithClientName(CONTRACT_VERSION.V2),
note: tinymanJSSDKConfig.getAppCallTxnNoteWithClientName(
CONTRACT_VERSION.V2,
params.appCallNoteExtraData
),
accounts: [poolAddress],
foreignAssets: [pool.asset1ID, pool.asset2ID],
suggestedParams
Expand Down

0 comments on commit b22e80e

Please sign in to comment.