Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pontem/liquidswap-sdk

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pontem/liquidswap-sdk - npm Package Compare versions

Comparing version 0.5.7 to 0.6.0

6

dist/tsc/constants/index.d.ts
export declare const MODULES_ACCOUNT = "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12";
export declare const RESOURCES_ACCOUNT = "0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948";
export declare const COINS_ACCOUNT = "0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9";
export declare const MODULES_V05_ACCOUNT = "0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e";
export declare const RESOURCES_V05_ACCOUNT = "0x61d2c22a6cb7831bee0f48363b0eec92369357aece0d1142062f7d5d85c7bef8";
export declare const COIN_INFO = "0x1::coin::CoinInfo";
export declare const COIN_STORE = "0x1::coin::CoinStore";
export declare const SCRIPTS_V1 = "scripts";
export declare const SCRIPTS_V2 = "scripts_v2";
export declare const VERSION_0 = 0;
export declare const VERSION_0_5 = 0.5;
export declare const NETWORKS_MODULES: {

@@ -7,0 +13,0 @@ Scripts: string;

10

dist/tsc/constants/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TOKENS_MAPPING = exports.NETWORKS_MODULES = exports.COIN_STORE = exports.COIN_INFO = exports.COINS_ACCOUNT = exports.RESOURCES_ACCOUNT = exports.MODULES_ACCOUNT = void 0;
exports.TOKENS_MAPPING = exports.NETWORKS_MODULES = exports.VERSION_0_5 = exports.VERSION_0 = exports.SCRIPTS_V2 = exports.SCRIPTS_V1 = exports.COIN_STORE = exports.COIN_INFO = exports.RESOURCES_V05_ACCOUNT = exports.MODULES_V05_ACCOUNT = exports.COINS_ACCOUNT = exports.RESOURCES_ACCOUNT = exports.MODULES_ACCOUNT = void 0;
exports.MODULES_ACCOUNT = '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12';
exports.RESOURCES_ACCOUNT = '0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948';
exports.COINS_ACCOUNT = '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9';
exports.MODULES_V05_ACCOUNT = '0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e';
exports.RESOURCES_V05_ACCOUNT = '0x61d2c22a6cb7831bee0f48363b0eec92369357aece0d1142062f7d5d85c7bef8';
exports.COIN_INFO = '0x1::coin::CoinInfo';
exports.COIN_STORE = '0x1::coin::CoinStore';
exports.SCRIPTS_V1 = 'scripts';
exports.SCRIPTS_V2 = 'scripts_v2';
exports.VERSION_0 = 0;
exports.VERSION_0_5 = 0.5;
exports.NETWORKS_MODULES = {

@@ -19,5 +25,5 @@ Scripts: `${exports.MODULES_ACCOUNT}::scripts_v2`,

BTC: '0xae478ff7d83ed072dbc5e264250e67ef58f57c99d89b447efd8a0a2e8b2be76e::coin::T',
WETH: '0xcc8a89c8dce9693d354449f1f73e60e14e347417854f029db5bc8e7454008abb::coin::T',
WETH: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH',
USDC: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC', // layerzero USDC
};
//# sourceMappingURL=index.js.map

7

dist/tsc/modules/SwapModule.d.ts
import Decimal from 'decimal.js';
import { SDK } from '../sdk';
import { IModule } from '../interfaces/IModule';
import { AptosPoolResource, AptosResourceType, TAptosTxPayload, CurveType } from '../types/aptos';
import { AptosPoolResource, AptosResourceType, CurveType, TAptosTxPayload } from '../types/aptos';
import { VERSION_0, VERSION_0_5 } from "../constants";
export declare type CalculateRatesParams = {

@@ -11,2 +12,3 @@ fromToken: AptosResourceType;

curveType: CurveType;
version?: typeof VERSION_0 | typeof VERSION_0_5;
};

@@ -22,4 +24,5 @@ export declare type CreateTXPayloadParams = {

curveType: CurveType;
version?: typeof VERSION_0 | typeof VERSION_0_5;
};
declare type GetLiquidityPoolResourceParams = Pick<CalculateRatesParams, 'fromToken' | 'toToken' | 'curveType'>;
declare type GetLiquidityPoolResourceParams = Pick<CalculateRatesParams, 'fromToken' | 'toToken' | 'curveType' | 'version'>;
export declare class SwapModule implements IModule {

@@ -26,0 +29,0 @@ protected _sdk: SDK;

@@ -6,2 +6,4 @@ "use strict";

const utils_1 = require("../utils");
const constants_1 = require("../constants");
const contracts_1 = require("../utils/contracts");
class SwapModule {

@@ -96,3 +98,5 @@ constructor(sdk) {

const { modules } = this.sdk.networkOptions;
const isUnchecked = params.curveType === 'stable' && params.stableSwapType === 'normal';
const isUnchecked = params.version === constants_1.VERSION_0 &&
params.curveType === 'stable' &&
params.stableSwapType === 'normal';
const functionName = (0, utils_1.composeType)(modules.Scripts, isUnchecked

@@ -103,3 +107,3 @@ ? 'swap_unchecked'

: 'swap_into');
const curve = curves[params.curveType];
const curve = (0, contracts_1.getCurve)(params.curveType, curves, params.version);
const typeArguments = [params.fromToken, params.toToken, curve];

@@ -126,5 +130,9 @@ const fromAmount = params.interactiveToken === 'from'

return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { resourceAccount, moduleAccount } = this.sdk.networkOptions;
const { resourceAccount, moduleAccount, resourceAccountV05, moduleAccountV05 } = this.sdk.networkOptions;
const curves = this.sdk.curves;
const modulesLiquidityPool = (0, utils_1.composeType)(moduleAccount, 'liquidity_pool', 'LiquidityPool');
const version = params.version;
const curve = (0, contracts_1.getCurve)(params.curveType, curves, version);
const moduleAcc = version === constants_1.VERSION_0_5 ? moduleAccountV05 : moduleAccount;
const resourceAcc = version === constants_1.VERSION_0_5 ? resourceAccountV05 : resourceAccount;
const modulesLiquidityPool = (0, utils_1.composeType)(moduleAcc, 'liquidity_pool', 'LiquidityPool');
function getPoolStr(coinX, coinY, curve) {

@@ -136,3 +144,2 @@ const [sortedX, sortedY] = (0, utils_1.is_sorted)(coinX, coinY)

}
const curve = curves[params.curveType];
const liquidityPoolType = getPoolStr(params.fromToken, params.toToken, curve);

@@ -142,3 +149,3 @@ let liquidityPoolResource;

liquidityPoolResource =
yield this.sdk.Resources.fetchAccountResource(resourceAccount, liquidityPoolType);
yield this.sdk.Resources.fetchAccountResource(resourceAcc, liquidityPoolType);
}

@@ -145,0 +152,0 @@ catch (e) {

@@ -15,2 +15,4 @@ import { AptosClient } from 'aptos';

moduleAccount?: string;
moduleAccountV05?: string;
resourceAccountV05?: string;
}

@@ -21,5 +23,7 @@ export interface SdkOptions {

}
interface ICurves {
export interface ICurves {
stable: string;
uncorrelated: string;
stableV05: string;
uncorrelatedV05: string;
}

@@ -26,0 +30,0 @@ export declare class SDK {

@@ -18,6 +18,8 @@ "use strict";

moduleAccount: constants_1.MODULES_ACCOUNT,
moduleAccountV05: constants_1.MODULES_V05_ACCOUNT,
resourceAccountV05: constants_1.RESOURCES_V05_ACCOUNT
};
class SDK {
constructor(options) {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e, _f;
this._networkOptions = initialNetworkOptions;

@@ -37,2 +39,8 @@ if (options.networkOptions) {

}
if ((_e = options.networkOptions) === null || _e === void 0 ? void 0 : _e.moduleAccountV05) {
this._networkOptions.moduleAccountV05 = options.networkOptions.moduleAccountV05;
}
if ((_f = options.networkOptions) === null || _f === void 0 ? void 0 : _f.resourceAccountV05) {
this._networkOptions.resourceAccountV05 = options.networkOptions.resourceAccountV05;
}
}

@@ -45,3 +53,5 @@ this._client = new aptos_1.AptosClient(options.nodeUrl);

uncorrelated: `${this._networkOptions.moduleAccount}::curves::Uncorrelated`,
stable: `${this._networkOptions.moduleAccount}::curves::Stable`
stable: `${this._networkOptions.moduleAccount}::curves::Stable`,
uncorrelatedV05: `${this._networkOptions.moduleAccountV05}::curves::Uncorrelated`,
stableV05: `${this._networkOptions.moduleAccountV05}::curves::Stable`
};

@@ -48,0 +58,0 @@ }

import Decimal from 'decimal.js';
import { ICurves } from '../sdk';
import { CurveType } from "../types/aptos";
/**

@@ -24,1 +26,20 @@ * Compare sorting between two coin types

}): boolean;
/**
* Get Script Modules Name for a Contract Version
*
* @throws Unknown contract version requested
*
* @param contract version number
* @returns script with scripts module name value
*/
export declare function getScriptsFor(version: number): string;
/**
* Compute full curve type for given contract version
*
* @param type short name of curve
* @param contract version
* @param curves curves from sdk
* @returns curve full type
*
*/
export declare function getCurve(type: CurveType, curves: ICurves, contract?: number): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAptosType = exports.extractAddressFromType = exports.withSlippage = exports.composeType = exports.is_sorted = void 0;
exports.getCurve = exports.getScriptsFor = exports.checkAptosType = exports.extractAddressFromType = exports.withSlippage = exports.composeType = exports.is_sorted = void 0;
const tslib_1 = require("tslib");
const buffer_1 = require("buffer");
const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
const constants_1 = require("../constants");
const hex_1 = require("./hex");

@@ -157,2 +158,44 @@ const EQUAL = 0;

exports.checkAptosType = checkAptosType;
/**
* Get Script Modules Name for a Contract Version
*
* @throws Unknown contract version requested
*
* @param contract version number
* @returns script with scripts module name value
*/
function getScriptsFor(version) {
if (version === constants_1.VERSION_0_5)
return constants_1.SCRIPTS_V1;
switch (version) {
case constants_1.VERSION_0:
return constants_1.SCRIPTS_V2;
case constants_1.VERSION_0_5:
return constants_1.SCRIPTS_V1;
}
throw new Error('Unknown contract version requested');
}
exports.getScriptsFor = getScriptsFor;
/**
* Compute full curve type for given contract version
*
* @param type short name of curve
* @param contract version
* @param curves curves from sdk
* @returns curve full type
*
*/
function getCurve(type, curves, contract) {
if (contract === constants_1.VERSION_0_5) {
if (type === 'stable') {
return curves.stableV05;
}
return curves.uncorrelatedV05;
}
if (type === 'stable') {
return curves.stable;
}
return curves.uncorrelated;
}
exports.getCurve = getCurve;
//# sourceMappingURL=contracts.js.map
export { getCoinInWithFees, getCoinOutWithFees, getCoinsOutWithFeesStable, getCoinsInWithFeesStable, } from './swap-math';
export { is_sorted, withSlippage, composeType, extractAddressFromType, } from './contracts';
export { calcReceivedLP, calcOutputBurnLiquidity, getOptimalLiquidityAmount, getPoolLpStr, getPoolStr, } from './liquidity';
export { calcReceivedLP, calcOutputBurnLiquidity, getOptimalLiquidityAmount, getPoolStr, } from './liquidity';
export { d, decimalsMultiplier, convertValueToDecimal, convertDecimalToFixedString, } from './numbers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDecimalToFixedString = exports.convertValueToDecimal = exports.decimalsMultiplier = exports.d = exports.getPoolStr = exports.getPoolLpStr = exports.getOptimalLiquidityAmount = exports.calcOutputBurnLiquidity = exports.calcReceivedLP = exports.extractAddressFromType = exports.composeType = exports.withSlippage = exports.is_sorted = exports.getCoinsInWithFeesStable = exports.getCoinsOutWithFeesStable = exports.getCoinOutWithFees = exports.getCoinInWithFees = void 0;
exports.convertDecimalToFixedString = exports.convertValueToDecimal = exports.decimalsMultiplier = exports.d = exports.getPoolStr = exports.getOptimalLiquidityAmount = exports.calcOutputBurnLiquidity = exports.calcReceivedLP = exports.extractAddressFromType = exports.composeType = exports.withSlippage = exports.is_sorted = exports.getCoinsInWithFeesStable = exports.getCoinsOutWithFeesStable = exports.getCoinOutWithFees = exports.getCoinInWithFees = void 0;
var swap_math_1 = require("./swap-math");

@@ -18,3 +18,2 @@ Object.defineProperty(exports, "getCoinInWithFees", { enumerable: true, get: function () { return swap_math_1.getCoinInWithFees; } });

Object.defineProperty(exports, "getOptimalLiquidityAmount", { enumerable: true, get: function () { return liquidity_1.getOptimalLiquidityAmount; } });
Object.defineProperty(exports, "getPoolLpStr", { enumerable: true, get: function () { return liquidity_1.getPoolLpStr; } });
Object.defineProperty(exports, "getPoolStr", { enumerable: true, get: function () { return liquidity_1.getPoolStr; } });

@@ -21,0 +20,0 @@ var numbers_1 = require("./numbers");

@@ -26,3 +26,2 @@ import { Decimal } from 'decimal.js';

export declare function getOptimalLiquidityAmount(xDesired: Decimal, xReserve: Decimal, yReserve: Decimal): Decimal;
export declare function getPoolLpStr(coinX: string, coinY: string, curve: string): string;
export declare function getPoolStr(coinX: string, coinY: string, curve: string, modulesLiquidityPool: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPoolStr = exports.getPoolLpStr = exports.getOptimalLiquidityAmount = exports.calcOutputBurnLiquidity = exports.calcReceivedLP = void 0;
exports.getPoolStr = exports.getOptimalLiquidityAmount = exports.calcOutputBurnLiquidity = exports.calcReceivedLP = void 0;
const decimal_js_1 = require("decimal.js");
const numbers_1 = require("./numbers");
const constants_1 = require("../constants");
const contracts_1 = require("./contracts");

@@ -54,11 +53,2 @@ /**

exports.getOptimalLiquidityAmount = getOptimalLiquidityAmount;
function getPoolLpStr(coinX, coinY, curve) {
const [sortedX, sortedY] = (0, contracts_1.is_sorted)(coinX, coinY)
? [coinX, coinY]
: [coinY, coinX];
return (0, contracts_1.composeType)(
//
constants_1.RESOURCES_ACCOUNT, 'lp_coin', 'LP', [sortedX, sortedY, curve]);
}
exports.getPoolLpStr = getPoolLpStr;
function getPoolStr(coinX, coinY, curve, modulesLiquidityPool) {

@@ -65,0 +55,0 @@ const [sortedX, sortedY] = (0, contracts_1.is_sorted)(coinX, coinY)

{
"name": "@pontem/liquidswap-sdk",
"version": "0.5.7",
"version": "0.6.0",
"description": "SDK to use LiquidSwap functions",

@@ -5,0 +5,0 @@ "author": "Igor Demko <igor@pontem.network>",

@@ -60,2 +60,6 @@ <a name="readme-top"></a>

},
resourceAccount: '0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948',
moduleAccount: '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12',
moduleAccountV05: '0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e',
resourceAccountV05: '0x61d2c22a6cb7831bee0f48363b0eec92369357aece0d1142062f7d5d85c7bef8'
}

@@ -296,2 +300,57 @@ */

<details>
<summary>Pools v.0.5: Swap 0.8 LayerZero USDT to LayerZero USDC</summary>
```typescript
(async () => {
// Get USDT amount
try {
const output = await sdk.Swap.calculateRates({
fromToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC', //layerzero USDC
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT', // layerzero USDT
amount: 800000, // 0.8 USDC, or you can use convertValueToDecimal(0.8, 6)
curveType: 'stable', // can be 'uncorrelated' or 'stable'
interactiveToken: 'from', // which token is 'base' to calculate other token rate.
version: 0.5 // optional, version could be only 0 or 0.5. If not provided version is 0
})
console.log(output) // '601018' (0.601018 USDT)
// Generate TX payload for swap 0.8 USDC to maximum 0.601018 USDT
// and minimum 0.598013 USDT (with slippage -0.5%)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT', // layerzero USDT
fromAmount: 800000, // 0.8 USDT, or you can use convertValueToDecimal(0.8, 6)
toAmount: 601018, // 0.601018 USDC, or you can use convertValueToDecimal(0.601018, 6)
interactiveToken: 'from',
slippage: 0.005, // 0.5% (1 - 100%, 0 - 0%)
stableSwapType: 'high',
curveType: 'stable',
version: 0.5,
})
console.log(txPayload);
} catch(e) {
console.log(e)
}
/**
Output:
{
"arguments": [
"800000",
"598013"
],
"function": "0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::scripts::swap",
"type": "entry_function_payload",
"type_arguments": [
"0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
"0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
"0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Stable"
]
}
*/
})()
```
</details>
<details>
<summary>Creating Liquidity Pool for pair APTOS / lzUSDC</summary>

@@ -298,0 +357,0 @@

export const MODULES_ACCOUNT = '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12';
export const RESOURCES_ACCOUNT = '0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948';
export const COINS_ACCOUNT = '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9';
export const MODULES_V05_ACCOUNT = '0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e';
export const RESOURCES_V05_ACCOUNT = '0x61d2c22a6cb7831bee0f48363b0eec92369357aece0d1142062f7d5d85c7bef8';

@@ -8,2 +10,7 @@ export const COIN_INFO = '0x1::coin::CoinInfo';

export const SCRIPTS_V1 = 'scripts';
export const SCRIPTS_V2 = 'scripts_v2';
export const VERSION_0 = 0;
export const VERSION_0_5 = 0.5;
export const NETWORKS_MODULES = {

@@ -20,4 +27,4 @@ Scripts: `${MODULES_ACCOUNT}::scripts_v2`,

BTC: '0xae478ff7d83ed072dbc5e264250e67ef58f57c99d89b447efd8a0a2e8b2be76e::coin::T', // wormhole wrapped BTC
WETH: '0xcc8a89c8dce9693d354449f1f73e60e14e347417854f029db5bc8e7454008abb::coin::T', // wormhole WETH
WETH: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH', // LayerZero WETH
USDC: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC', // layerzero USDC
};
import Decimal from 'decimal.js';
import { SDK } from '../sdk';
import { IModule } from '../interfaces/IModule';
import {SDK} from '../sdk';
import {IModule} from '../interfaces/IModule';
import {AptosCoinInfoResource, AptosPoolResource, AptosResourceType, CurveType, TAptosTxPayload,} from '../types/aptos';
import {
AptosCoinInfoResource,
AptosPoolResource,
AptosResourceType,
TAptosTxPayload,
CurveType,
} from '../types/aptos';
import {
withSlippage,
composeType,
d,
extractAddressFromType,
getCoinInWithFees,
getCoinOutWithFees,
getCoinsInWithFeesStable,
getCoinsOutWithFeesStable,
getCoinsInWithFeesStable,
d,
is_sorted,
withSlippage,
} from '../utils';
import { VERSION_0, VERSION_0_5 } from "../constants";
import { getCurve } from "../utils/contracts";

@@ -30,2 +26,3 @@ export type CalculateRatesParams = {

curveType: CurveType;
version?: typeof VERSION_0 | typeof VERSION_0_5;
};

@@ -42,5 +39,6 @@

curveType: CurveType;
version?: typeof VERSION_0 | typeof VERSION_0_5;
}
type GetLiquidityPoolResourceParams = Pick<CalculateRatesParams, 'fromToken' | 'toToken' | 'curveType'>;
type GetLiquidityPoolResourceParams = Pick<CalculateRatesParams, 'fromToken' | 'toToken' | 'curveType' | 'version'>;

@@ -176,4 +174,9 @@ export class SwapModule implements IModule {

const isUnchecked =
params.curveType === 'stable' && params.stableSwapType === 'normal';
params.version === VERSION_0 &&
params.curveType === 'stable' &&
params.stableSwapType === 'normal';

@@ -189,3 +192,3 @@ const functionName = composeType(

const curve = curves[params.curveType];
const curve = getCurve(params.curveType, curves, params.version);

@@ -218,7 +221,14 @@ const typeArguments = [params.fromToken, params.toToken, curve];

async getLiquidityPoolResource(params: GetLiquidityPoolResourceParams) {
const { resourceAccount, moduleAccount } = this.sdk.networkOptions;
const { resourceAccount, moduleAccount, resourceAccountV05, moduleAccountV05 } = this.sdk.networkOptions;
const curves = this.sdk.curves;
const version = params.version;
const curve = getCurve(params.curveType, curves, version);
const moduleAcc = version === VERSION_0_5 ? moduleAccountV05 : moduleAccount;
const resourceAcc = version === VERSION_0_5 ? resourceAccountV05 : resourceAccount;
const modulesLiquidityPool = composeType(
moduleAccount,
moduleAcc,
'liquidity_pool',

@@ -234,3 +244,2 @@ 'LiquidityPool',

}
const curve = curves[params.curveType];

@@ -248,3 +257,3 @@ const liquidityPoolType = getPoolStr(

await this.sdk.Resources.fetchAccountResource<AptosPoolResource>(
resourceAccount,
resourceAcc,
liquidityPoolType,

@@ -251,0 +260,0 @@ );

@@ -6,3 +6,3 @@ import { AptosClient } from 'aptos';

import { LiquidityModule } from './modules/LiquidityModule';
import { NETWORKS_MODULES, MODULES_ACCOUNT, RESOURCES_ACCOUNT } from './constants';
import { NETWORKS_MODULES, MODULES_ACCOUNT, RESOURCES_ACCOUNT, MODULES_V05_ACCOUNT, RESOURCES_V05_ACCOUNT } from './constants';

@@ -18,2 +18,4 @@ const initialNetworkOptions = {

moduleAccount: MODULES_ACCOUNT,
moduleAccountV05: MODULES_V05_ACCOUNT,
resourceAccountV05: RESOURCES_V05_ACCOUNT
};

@@ -30,2 +32,4 @@

moduleAccount?: string;
moduleAccountV05?: string;
resourceAccountV05?: string;
}

@@ -38,5 +42,7 @@

interface ICurves {
export interface ICurves {
stable: string;
uncorrelated: string;
stableV05: string;
uncorrelatedV05: string;
}

@@ -91,2 +97,8 @@

}
if (options.networkOptions?.moduleAccountV05) {
this._networkOptions.moduleAccountV05 = options.networkOptions.moduleAccountV05;
}
if (options.networkOptions?.resourceAccountV05) {
this._networkOptions.resourceAccountV05 = options.networkOptions.resourceAccountV05;
}
}

@@ -99,5 +111,7 @@ this._client = new AptosClient(options.nodeUrl);

uncorrelated: `${this._networkOptions.moduleAccount}::curves::Uncorrelated`,
stable: `${this._networkOptions.moduleAccount}::curves::Stable`
stable: `${this._networkOptions.moduleAccount}::curves::Stable`,
uncorrelatedV05: `${this._networkOptions.moduleAccountV05}::curves::Uncorrelated`,
stableV05: `${this._networkOptions.moduleAccountV05}::curves::Stable`
}
}
}

@@ -1,2 +0,10 @@

import { MODULES_ACCOUNT, RESOURCES_ACCOUNT, TOKENS_MAPPING } from '../constants';
import {
MODULES_ACCOUNT,
MODULES_V05_ACCOUNT,
RESOURCES_ACCOUNT,
RESOURCES_V05_ACCOUNT,
TOKENS_MAPPING,
VERSION_0,
VERSION_0_5
} from '../constants';
import SDK from '../main';

@@ -11,3 +19,5 @@ import { convertValueToDecimal } from '../utils';

resourceAccount: RESOURCES_ACCOUNT,
moduleAccount: MODULES_ACCOUNT
moduleAccount: MODULES_ACCOUNT,
resourceAccountV05: RESOURCES_V05_ACCOUNT,
moduleAccountV05: MODULES_V05_ACCOUNT
}

@@ -18,2 +28,110 @@ });

test('calculateRates (from mode) stable version v0.5', async () => {
const output = await sdk.Swap.calculateRates({
fromToken: TOKENS_MAPPING.USDC,
toToken: TOKENS_MAPPING.USDT,
amount: 1000000, // 1 USDC
curveType: 'stable',
interactiveToken: 'from',
version: VERSION_0_5
});
console.log(`1000000 LayerZero USDC → ${output} LayerZero USDT`);
expect(typeof output).toBe('string');
expect(output.length).toBeGreaterThan(0);
});
test('calculateRates (to mode) stable version v0.5', async () => {
const output = await sdk.Swap.calculateRates({
fromToken: TOKENS_MAPPING.USDC,
toToken: TOKENS_MAPPING.USDT,
amount: 100000, // 0.1 USDT
curveType: 'stable',
interactiveToken: 'to',
version: VERSION_0_5
});
console.log(`100000 LayerZero USDT → ${output} LayerZero USDC`);
expect(typeof output).toBe('string');
expect(output.length).toBeGreaterThan(0);
});
test('calculateRates (from mode) uncorrelated version v0.5', async () => {
const output = await sdk.Swap.calculateRates({
fromToken: TOKENS_MAPPING.USDT,
toToken: TOKENS_MAPPING.WETH,
amount: 150000, // 0.15 USDT
curveType: 'uncorrelated',
interactiveToken: 'from',
version: VERSION_0_5
});
console.log(`150000 LayerZero USDT → ${output} LayerZero WETH`);
expect(typeof output).toBe('string');
expect(output.length).toBeGreaterThan(0);
});
test('calculateRates (to mode) uncorrelated version v0.5', async () => {
const output = await sdk.Swap.calculateRates({
fromToken: TOKENS_MAPPING.WETH,
toToken: TOKENS_MAPPING.USDT,
amount: 150000, // 0.15 USDT
curveType: 'uncorrelated',
interactiveToken: 'to',
version: VERSION_0_5
});
console.log(`150000 LayerZero USDT → ${output} LayerZero WETH`);
expect(typeof output).toBe('string');
expect(output.length).toBeGreaterThan(0);
});
test('createSwapTransactionPayload (stable from mode high) v0.5', () => {
const output = sdk.Swap.createSwapTransactionPayload({
fromToken: TOKENS_MAPPING.USDT,
toToken: TOKENS_MAPPING.WETH,
fromAmount: 150000, // 0.15 layerzero USDT
toAmount: 146, // 0.0000146 wormhole WETH
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'high',
curveType: 'stable',
version: VERSION_0_5
});
expect(output).toStrictEqual({
type: 'entry_function_payload',
function:
'0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap',
type_arguments: [TOKENS_MAPPING.USDT, TOKENS_MAPPING.WETH, curves.stableV05],
arguments: ['150000', '145'],
});
});
test('createSwapTransactionPayload (stable from mode high) v0.5', () => {
const output = sdk.Swap.createSwapTransactionPayload({
fromToken: TOKENS_MAPPING.USDT,
toToken: TOKENS_MAPPING.WETH,
fromAmount: 150000, // 0.15 layerzero USDT
toAmount: 146, // 0.0000146 wormhole WETH
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'normal',
curveType: 'stable',
version: VERSION_0_5
});
expect(output).toStrictEqual({
type: 'entry_function_payload',
function:
'0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap',
type_arguments: [TOKENS_MAPPING.USDT, TOKENS_MAPPING.WETH, curves.stableV05],
arguments: ['150000', '145'],
});
});
test('calculateRates (from mode)', async () => {

@@ -26,2 +144,3 @@ const output = await sdk.Swap.calculateRates({

interactiveToken: 'from',
version: VERSION_0
});

@@ -42,2 +161,3 @@

interactiveToken: 'to',
version: VERSION_0
});

@@ -58,2 +178,3 @@

interactiveToken: 'from',
version: VERSION_0
});

@@ -75,2 +196,3 @@

interactiveToken: 'to',
version: VERSION_0
});

@@ -92,2 +214,3 @@ } catch (e) {

interactiveToken: 'to',
version: VERSION_0
});

@@ -105,2 +228,3 @@ } catch (e) {

interactiveToken: 'to',
version: VERSION_0
});

@@ -118,2 +242,3 @@ } catch (e) {

interactiveToken: 'to',
version: VERSION_0
});

@@ -133,2 +258,3 @@ } catch (e) {

interactiveToken: 'to',
version: VERSION_0
});

@@ -150,2 +276,3 @@ } catch (e) {

curveType: 'uncorrelated',
version: VERSION_0
});

@@ -176,2 +303,3 @@

curveType: 'uncorrelated',
version: VERSION_0
});

@@ -202,2 +330,3 @@

curveType: 'stable',
version: VERSION_0
});

@@ -224,2 +353,3 @@

curveType: 'stable',
version: VERSION_0
});

@@ -246,2 +376,3 @@

curveType: 'stable',
version: VERSION_0
});

@@ -268,2 +399,3 @@

curveType: 'stable',
version: VERSION_0
});

@@ -292,2 +424,3 @@

curveType: 'stable',
version: VERSION_0
});

@@ -310,2 +443,3 @@ } catch (e) {

curveType: 'stable',
version: VERSION_0
});

@@ -324,2 +458,3 @@ } catch (e) {

curveType: 'uncorrelated',
version: VERSION_0
});

@@ -338,2 +473,3 @@

curveType: 'uncorrelated',
version: VERSION_0
});

@@ -340,0 +476,0 @@

import { Buffer } from 'buffer';
import Decimal from 'decimal.js';
import { ICurves } from '../sdk';
import {
VERSION_0_5,
VERSION_0,
SCRIPTS_V1,
SCRIPTS_V2,
} from '../constants';
import { checkAddress } from './hex';
import {CurveType} from "../types/aptos";

@@ -200,1 +210,42 @@ const EQUAL = 0;

}
/**
* Get Script Modules Name for a Contract Version
*
* @throws Unknown contract version requested
*
* @param contract version number
* @returns script with scripts module name value
*/
export function getScriptsFor(version: number): string {
if (version === VERSION_0_5) return SCRIPTS_V1;
switch (version) {
case VERSION_0:
return SCRIPTS_V2;
case VERSION_0_5:
return SCRIPTS_V1;
}
throw new Error('Unknown contract version requested');
}
/**
* Compute full curve type for given contract version
*
* @param type short name of curve
* @param contract version
* @param curves curves from sdk
* @returns curve full type
*
*/
export function getCurve(type: CurveType, curves: ICurves, contract?: number): string {
if (contract === VERSION_0_5) {
if (type === 'stable') {
return curves.stableV05;
}
return curves.uncorrelatedV05;
}
if (type === 'stable') {
return curves.stable;
}
return curves.uncorrelated;
}

@@ -17,3 +17,2 @@ export {

getOptimalLiquidityAmount,
getPoolLpStr,
getPoolStr,

@@ -20,0 +19,0 @@ } from './liquidity';

import { Decimal } from 'decimal.js';
import { d } from './numbers';
import { RESOURCES_ACCOUNT } from '../constants';
import { is_sorted, composeType } from './contracts';

@@ -85,19 +84,2 @@

export function getPoolLpStr(
coinX: string,
coinY: string,
curve: string,
): string {
const [sortedX, sortedY] = is_sorted(coinX, coinY)
? [coinX, coinY]
: [coinY, coinX];
return composeType(
//
RESOURCES_ACCOUNT,
'lp_coin',
'LP',
[sortedX, sortedY, curve],
);
}
export function getPoolStr(

@@ -104,0 +86,0 @@ coinX: string,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc