This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from naviprotocol/Add-new-Dexes
add new Dexes
- Loading branch information
Showing
11 changed files
with
306 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
MNEMONIC = '' | ||
NAVI_DEX_AGGREGATOR_API_BASE_URL = '' # Required, default: https://aggregator-api.naviprotocol.io/find_routes | ||
|
||
# Optional in Sample/Demo.ts | ||
RPC = '' | ||
NAVI_DEX_AGGREGATOR_API_BASE_URL = '' | ||
MNEMONIC = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions"; | ||
import { config } from "../config"; | ||
|
||
export async function makeKriyaV2PTB(txb: Transaction, poolId: string, byAmountIn: boolean, coinA: any, amount: any, a2b: boolean, typeArguments: any) { | ||
|
||
const func = a2b ? 'swap_token_x' : 'swap_token_y'; | ||
|
||
const args = [ | ||
txb.object(poolId), | ||
coinA, | ||
typeof amount === 'number' ? txb.pure.u64(amount) : amount, | ||
txb.pure.u64(0), | ||
] | ||
|
||
const [coinB] = txb.moveCall({ | ||
target: `${config.KRIYA_V2_PACKAGEID}::spot_dex::${func}`, | ||
typeArguments: typeArguments, | ||
arguments: args, | ||
}) | ||
|
||
return coinB | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions"; | ||
import { config } from "../config"; | ||
|
||
export async function makeAftermathPTB(txb: Transaction, poolId: string, coinA: any, amountOut: any, a2b: boolean, typeArguments: any) { | ||
|
||
const args = [ | ||
txb.object(poolId), | ||
txb.object(config.AFTERMATH_POOLREGISTRY), | ||
txb.object(config.AFTERMATH_FEEVAULT), | ||
txb.object(config.AFTERMATH_TREASURY), | ||
txb.object(config.AFTERMATH_INSURANCE_FUND), | ||
txb.object(config.AFTERMATH_REFERRAL_VAULT), | ||
coinA, | ||
txb.pure.u64(amountOut), | ||
txb.pure.u64('800000000000000000'), // 80%, use https://suivision.xyz/txblock/AvASModFbU6Bmu6FNghqBsVqktnhB9QZKQjdYfnuxNvo?tab=Overview as an reference | ||
] | ||
|
||
const res = txb.moveCall({ | ||
target: `${config.AFTERMATH_PACKAGEID}::swap::swap_exact_in`, | ||
typeArguments: typeArguments, | ||
arguments: args, | ||
}) | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions"; | ||
import { config } from "../config"; | ||
|
||
export async function makeKriyaV3PTB(txb: Transaction, poolId: string, byAmountIn: boolean, coinA: any, amount: any, a2b: boolean, typeArguments: any) { | ||
|
||
const sqrtPriceLimit = BigInt(a2b ? '4295048016' : '79226673515401279992447579055') | ||
const args = [ | ||
txb.object(poolId), | ||
txb.pure.bool(a2b), | ||
txb.pure.bool(byAmountIn), | ||
typeof amount === 'number' ? txb.pure.u64(amount) : amount, | ||
txb.pure.u128(sqrtPriceLimit), | ||
txb.object(config.CLOCK_ADDRESS), | ||
txb.object(config.KRIYA_V3_VERSION), | ||
] | ||
const [receive_balance_a, receive_balance_b, receipt] = txb.moveCall({ | ||
target: `${config.KRIYA_V3_PACKAGEID}::trade::flash_swap`, | ||
typeArguments: typeArguments, | ||
arguments: args, | ||
}) | ||
|
||
if (a2b) { | ||
txb.moveCall({ | ||
target: '0x2::balance::destroy_zero', | ||
arguments: [receive_balance_a], | ||
typeArguments: [typeArguments[0]] | ||
}) | ||
|
||
let BalanceA = txb.moveCall({ | ||
target: "0x2::coin::into_balance", | ||
arguments: [coinA], | ||
typeArguments: [typeArguments[0]], | ||
}); | ||
|
||
const [BalanceB] = txb.moveCall({ | ||
target: '0x2::balance::zero', | ||
typeArguments: [typeArguments[1]] | ||
}) | ||
|
||
txb.moveCall({ | ||
target: `${config.KRIYA_V3_PACKAGEID}::trade::repay_flash_swap`, | ||
arguments: [ | ||
txb.object(poolId), | ||
receipt, | ||
|
||
BalanceA, | ||
BalanceB, | ||
txb.object(config.KRIYA_V3_VERSION), | ||
], | ||
typeArguments: typeArguments | ||
}) | ||
|
||
const receiveCoin: any = txb.moveCall({ | ||
target: `0x2::coin::from_balance`, | ||
arguments: [receive_balance_b], | ||
typeArguments: [typeArguments[1]] | ||
}) | ||
return receiveCoin | ||
} | ||
|
||
txb.moveCall({ | ||
target: '0x2::balance::destroy_zero', | ||
arguments: [receive_balance_b], | ||
typeArguments: [typeArguments[1]] | ||
}) | ||
|
||
let BalanceB = txb.moveCall({ | ||
target: "0x2::coin::into_balance", | ||
arguments: [coinA], | ||
typeArguments: [typeArguments[1]], | ||
}); | ||
|
||
const [BalanceA] = txb.moveCall({ | ||
target: '0x2::balance::zero', | ||
typeArguments: [typeArguments[0]] | ||
}) | ||
|
||
txb.moveCall({ | ||
target: `${config.KRIYA_V3_PACKAGEID}::trade::repay_flash_swap`, | ||
arguments: [ | ||
txb.object(poolId), | ||
receipt, | ||
BalanceA, | ||
BalanceB, | ||
txb.object(config.KRIYA_V3_VERSION), | ||
], | ||
typeArguments: typeArguments | ||
}) | ||
|
||
const receiveCoin: any = txb.moveCall({ | ||
target: `0x2::coin::from_balance`, | ||
arguments: [receive_balance_a], | ||
typeArguments: [typeArguments[0]] | ||
}) | ||
return receiveCoin | ||
} | ||
|
||
|
||
|
Oops, something went wrong.