You can use the provideLiquidityWithFixedAmount()
function to provide liquidity to an existing position.
A position can be opened by using either openPosition()
or openPositionWithFixedAmount()
.
Example
const originalStdoutWrite = process.stdout.write;
process.stdout.write = () => true;
import { OnChainCalls, QueryChain } from "@firefly-exchange/library-sui/dist/src/spot";
import { ClmmPoolUtil } from "@firefly-exchange/library-sui/dist/src/spot/clmm";
import { Ed25519Keypair, SuiClient, toBigNumberStr } from "@firefly-exchange/library-sui";
import { mainnet } from './config'
import { BN } from "bn.js";
process.stdout.write = originalStdoutWrite;
const client = new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" });
/// Parameters:
/// - privateKey : The private key of the user making the blockchain call
/// - posID : The position ID of the position whose liquidity is being provided
/// - coinAmount : The amount of CoinA willing to provide
/// This should be a decimal such as 1.7 as the decimal places are handled internally
/// - slippage : The difference between the expected price of a trade and the actual price at which it is executed.
/// This should be a number between 0 and 1, eg: 0.2
async function provideLiquidityWithFixedAmount(privateKey: string, posID: string, coinAmount: number, slippage: number){
const keyPair = Ed25519Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));
let qc = new QueryChain(client);
let pos = await qc.getPositionDetails(posID)
let pool = await qc.getPool(pos.pool_id);
let coinAmountBN = new BN(toBigNumberStr(coinAmount, pool.coin_a.decimals));
const curSqrtPrice = new BN(pool.current_sqrt_price);
const fix_amount_a = true;
let roundUp = true;
const liquidityInput = ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(
pos.lower_tick,
pos.upper_tick,
coinAmountBN,
fix_amount_a,
roundUp,
slippage,
curSqrtPrice
);
let oc = new OnChainCalls(client,mainnet, {signer: keyPair});
let resp = await oc.provideLiquidityWithFixedAmount(pool,posID,liquidityInput);
return resp
}
await provideLiquidityWithFixedAmount("<private key>","0xdfb915d248674db372adfc3caba299bf0ce2ed216a6475498eabbd28c92b6c84", 1, 0.5)
Response
{
"digest":"2TzNCePBNgMWDRT56ReixvVAtLWGiFGTvxbXVwchsjfK",
"transaction":{
"data":{
"messageVersion":"v1",
"transaction":{
"kind":"ProgrammableTransaction",
"inputs":[
{
"type":"pure",
"valueType":"u64",
"value":"600000000"
},
{
"type":"object",
"objectType":"immOrOwnedObject",
"objectId":"0xddf0c2d2bf9528ade09e00f0e9c869ec340314972ff59b771e6fbd428bbd1026",
"version":"409729491",
"digest":"5DHTeSXPefX9ZJQgqmddhtEBcYUqUSGAhrnpv6SY7gPq"
},
{
"type":"pure",
"valueType":"u64",
"value":"1376337"
},
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x0000000000000000000000000000000000000000000000000000000000000006",
"initialSharedVersion":"1",
"mutable":false
},
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
"initialSharedVersion":"406496849",
"mutable":false
},
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"initialSharedVersion":"406731547",
"mutable":true
},
{
"type":"object",
"objectType":"immOrOwnedObject",
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":"409729490",
"digest":"4JPLXTrmK17aVDexxKgC5sEXj1aWwQPNVh4xw2hGYcFt"
},
{
"type":"pure",
"valueType":"u64",
"value":"500000000"
},
{
"type":"pure",
"valueType":"u64",
"value":"600000000"
},
{
"type":"pure",
"valueType":"u64",
"value":"1376337"
},
{
"type":"pure",
"valueType":"bool",
"value":true
},
{
"type":"pure",
"valueType":"address",
"value":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
}
],
"transactions":[
{
"SplitCoins":[
"GasCoin",
[
{
"Input":0
}
]
]
},
{
"SplitCoins":[
{
"Input":1
},
[
{
"Input":2
}
]
]
},
{
"MoveCall":{
"package":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"module":"gateway",
"function":"provide_liquidity_with_fixed_amount",
"type_arguments":[
"0x2::sui::SUI",
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
],
"arguments":[
{
"Input":3
},
{
"Input":4
},
{
"Input":5
},
{
"Input":6
},
{
"Result":0
},
{
"Result":1
},
{
"Input":7
},
{
"Input":8
},
{
"Input":9
},
{
"Input":10
}
]
}
},
{
"TransferObjects":[
[
{
"Input":1
}
],
{
"Input":11
}
]
}
]
},
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"gasData":{
"payment":[
{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729491,
"digest":"GWyH45vTjwHMXTBaGdDbprfps7pNucxUHu5iufC4Etjk"
},
{
"objectId":"0x2946df189f3251b6738e9807f6e22a64638b96a3945eb56c2a570c54068b4ba1",
"version":409729491,
"digest":"2Ut8AsCg9y86p1nLG6qauPGCttNBZ2K5aW5ohGGYokFh"
}
],
"owner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"price":"750",
"budget":"5360420"
}
},
"txSignatures":[
"ADHJRGqnb/PpDzNaouiT3Bp8YkFkmnbiMvWCORbdzzNsQeP6GKKYAqmaSG24CFDzkFBTsmliKNTfObc7LgQOjARwIesVczXTTL/3Q5yIJFnOVC24GMSqzrdNJIY1vK3z9w=="
]
},
"effects":{
"messageVersion":"v1",
"status":{
"status":"success"
},
"executedEpoch":"566",
"gasUsed":{
"computationCost":"750000",
"storageCost":"23385200",
"storageRebate":"21481020",
"nonRefundableStorageFee":"216980"
},
"modifiedAtVersions":[
{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"sequenceNumber":"409729491"
},
{
"objectId":"0x2946df189f3251b6738e9807f6e22a64638b96a3945eb56c2a570c54068b4ba1",
"sequenceNumber":"409729491"
},
{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"sequenceNumber":"409729491"
},
{
"objectId":"0x414e64df93e359ac4c6a8c0b1dbaf3f5d097cc5b761027f471bb9390f66a2490",
"sequenceNumber":"409729491"
},
{
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"sequenceNumber":"409729490"
},
{
"objectId":"0xb9959c4b05873cce0b7ff3579715e815e73edc558729326206daa0358bd693ec",
"sequenceNumber":"409729491"
},
{
"objectId":"0xddf0c2d2bf9528ade09e00f0e9c869ec340314972ff59b771e6fbd428bbd1026",
"sequenceNumber":"409729491"
}
],
"sharedObjects":[
{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":409729491,
"digest":"EWGegJkhU36hpMPFfQUAo2YNZcP4adEWoTDr6j69WjDD"
},
{
"objectId":"0x0000000000000000000000000000000000000000000000000000000000000006",
"version":158550802,
"digest":"43eH21RKBdHkTizjacf55pzDTGz4piVfrVVcs6xF6SWG"
},
{
"objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
"version":409452196,
"digest":"cHY3mzy38rXW9RSBJZFvBuGA95wpNTjZet4NR136suv"
}
],
"transactionDigest":"2TzNCePBNgMWDRT56ReixvVAtLWGiFGTvxbXVwchsjfK",
"created":[
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0xab0e50b7f1c07145e36db22ae56b603b8825195919e82ca07a46a77cd03ceae0",
"version":409729492,
"digest":"AHpHTWHkJfurNTkqhGZA5YSrKu8E9NCge8u69MUy3EZh"
}
},
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0xf8049f908663106d14a7cdafa138f9d6201a242bd5705230e44249f785be4f37",
"version":409729492,
"digest":"EkhTrd6U9gffq6bEBjAPKn999zCZnjG4EWGdWmZArmKT"
}
}
],
"mutated":[
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729492,
"digest":"2NWSHwSkTdzieseinDn6CfHNiYhe7G6QhZ6yUtEtMAaC"
}
},
{
"owner":{
"Shared":{
"initial_shared_version":406731547
}
},
"reference":{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":409729492,
"digest":"hu81kfKLQs7b8nrmxCjcfbBAC2Lp4Kcz35KBesBbWHw"
}
},
{
"owner":{
"ObjectOwner":"0x693c650ba84b5ad1234ebe85a557555576cc7a164bb1df7a1c3a9192ed2cb528"
},
"reference":{
"objectId":"0x414e64df93e359ac4c6a8c0b1dbaf3f5d097cc5b761027f471bb9390f66a2490",
"version":409729492,
"digest":"BMTiHw3WaAp9Eu1LtdupjZGPzzphj8T4k2YdhFK7tp3S"
}
},
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":409729492,
"digest":"2vchmeNdpYzqYhgorDMBz5QNhnrAZmcFssiDYhoJwtJT"
}
},
{
"owner":{
"ObjectOwner":"0x693c650ba84b5ad1234ebe85a557555576cc7a164bb1df7a1c3a9192ed2cb528"
},
"reference":{
"objectId":"0xb9959c4b05873cce0b7ff3579715e815e73edc558729326206daa0358bd693ec",
"version":409729492,
"digest":"J221CBqwdg2GDVSaLm1qtunXaqpSKEhmhoASnp1NtuZ1"
}
},
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0xddf0c2d2bf9528ade09e00f0e9c869ec340314972ff59b771e6fbd428bbd1026",
"version":409729492,
"digest":"BUxwNnSGoP77g3hLDztELLzW7Ferh3uAJSSA1zQGxbfp"
}
}
],
"deleted":[
{
"objectId":"0x2946df189f3251b6738e9807f6e22a64638b96a3945eb56c2a570c54068b4ba1",
"version":409729492,
"digest":"7gyGAp71YXQRoxmFBaHxofQXAipvgHyBKPyxmdSJxyvz"
}
],
"gasObject":{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729492,
"digest":"2NWSHwSkTdzieseinDn6CfHNiYhe7G6QhZ6yUtEtMAaC"
}
},
"eventsDigest":"D8wKNQHYYdHzF4VTFsbo3PkTtvHxNY7sWPxBAPGqbrNx",
"dependencies":[
"49puDQZwHRnu7zYoARCjco1dFKMiK7LVSS8B5Si1yVdh",
"7DkJSrf5sPWGxqHbH2X1wXwFcftRm6myhJJnuTJbaMYr",
"CUQmrEssKtB8WxBYj3YQZJCrFTTDLqz3UWq1nRiWGCLS",
"Ck6TioQsgyRe8WWmftAsodTPT7PNVysHJsWjciDfbxXR",
"G8bfecxuKSH4aUvt1R7SGRoKe77Mif63RvY3SZ5Kcgn7",
"GH4YJPYoWE9fMXc1ZaM3jSPj17dh7MWyMJrmUjuffqnE",
"HzzEA9X29bCpPE7AJqoxN8zUgefPHztVJu1c73ScgxGa"
]
},
"events":[
{
"id":{
"txDigest":"2TzNCePBNgMWDRT56ReixvVAtLWGiFGTvxbXVwchsjfK",
"eventSeq":"0"
},
"packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"transactionModule":"gateway",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"type":"0xbc70b10012a01c00fda8957dbaa1f2b83683414f55e22341792b081fdffa9baa::events::TickUpdate",
"parsedJson":{
"index":{
"bits":4294904096
},
"liquidity_gross":"1805771496",
"liquidity_net":{
"bits":"1805771496"
}
},
"bcs":"F7PuH4bcWrh6PZiRy9SRNmamrFUrcxfoQW3YwefCzsM7cKR9H"
},
{
"id":{
"txDigest":"2TzNCePBNgMWDRT56ReixvVAtLWGiFGTvxbXVwchsjfK",
"eventSeq":"1"
},
"packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"transactionModule":"gateway",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"type":"0xbc70b10012a01c00fda8957dbaa1f2b83683414f55e22341792b081fdffa9baa::events::TickUpdate",
"parsedJson":{
"index":{
"bits":4294905176
},
"liquidity_gross":"1805771496",
"liquidity_net":{
"bits":"340282366920938463463374607429962439960"
}
},
"bcs":"fnErMjDn66ns9FTgBLBbydtTS9b3WmFgavTCNSD7xLNFVdKGr"
},
{
"id":{
"txDigest":"2TzNCePBNgMWDRT56ReixvVAtLWGiFGTvxbXVwchsjfK",
"eventSeq":"2"
},
"packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"transactionModule":"gateway",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"type":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::events::LiquidityProvided",
"parsedJson":{
"after_liquidity":"1916410938844",
"before_liquidity":"1915508053096",
"coin_a_amount":"500000000",
"coin_b_amount":"1146947",
"current_sqrt_price":"806173570447208900",
"current_tick_index":{
"bits":4294904685
},
"liquidity":"902885748",
"lower_tick":{
"bits":4294904096
},
"pool_coin_a_amount":"777090269450",
"pool_coin_b_amount":"1294421202",
"pool_id":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"position_id":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"sequence_number":"3616",
"upper_tick":{
"bits":4294905176
}
},
"bcs":"5kVwQ3ddA3xJAixXZ7BzsmaT4o9mYh4JoTZvAP3bEBG96YFb5EbFsNEFSRn7bkBFJMFij1csGASdHZRzikTHiBrzFKNZZkuMuFtYpX5AvtBPncC44CqRgnwcRmGjRjNZBhc3KdXwX2haGV4Bn8Yr7XjrufyWceEaExjnKAzshuyvab6wypRHCToz5Tj5xY1pLkw3DQyoR5F8jYGg7n7z7XDtqcaWZsq1qxVYqTVNurpHSDUEX1mDVKv2Rfs3g5KMZ"
}
],
"objectChanges":[
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0x2::sui::SUI>",
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":"409729492",
"previousVersion":"409729491",
"digest":"2NWSHwSkTdzieseinDn6CfHNiYhe7G6QhZ6yUtEtMAaC"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"Shared":{
"initial_shared_version":406731547
}
},
"objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::pool::Pool<0x2::sui::SUI, 0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":"409729492",
"previousVersion":"409729491",
"digest":"hu81kfKLQs7b8nrmxCjcfbBAC2Lp4Kcz35KBesBbWHw"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"ObjectOwner":"0x693c650ba84b5ad1234ebe85a557555576cc7a164bb1df7a1c3a9192ed2cb528"
},
"objectType":"0x2::dynamic_field::Field<0x714a63a0dba6da4f017b42d5d0fb78867f18bcde904868e51d951a5a6f5b7f57::i32::I32, 0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::tick::TickInfo>",
"objectId":"0x414e64df93e359ac4c6a8c0b1dbaf3f5d097cc5b761027f471bb9390f66a2490",
"version":"409729492",
"previousVersion":"409729491",
"digest":"BMTiHw3WaAp9Eu1LtdupjZGPzzphj8T4k2YdhFK7tp3S"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::position::Position",
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":"409729492",
"previousVersion":"409729490",
"digest":"2vchmeNdpYzqYhgorDMBz5QNhnrAZmcFssiDYhoJwtJT"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"ObjectOwner":"0x693c650ba84b5ad1234ebe85a557555576cc7a164bb1df7a1c3a9192ed2cb528"
},
"objectType":"0x2::dynamic_field::Field<0x714a63a0dba6da4f017b42d5d0fb78867f18bcde904868e51d951a5a6f5b7f57::i32::I32, 0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::tick::TickInfo>",
"objectId":"0xb9959c4b05873cce0b7ff3579715e815e73edc558729326206daa0358bd693ec",
"version":"409729492",
"previousVersion":"409729491",
"digest":"J221CBqwdg2GDVSaLm1qtunXaqpSKEhmhoASnp1NtuZ1"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
"objectId":"0xddf0c2d2bf9528ade09e00f0e9c869ec340314972ff59b771e6fbd428bbd1026",
"version":"409729492",
"previousVersion":"409729491",
"digest":"BUxwNnSGoP77g3hLDztELLzW7Ferh3uAJSSA1zQGxbfp"
},
{
"type":"created",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
"objectId":"0xab0e50b7f1c07145e36db22ae56b603b8825195919e82ca07a46a77cd03ceae0",
"version":"409729492",
"digest":"AHpHTWHkJfurNTkqhGZA5YSrKu8E9NCge8u69MUy3EZh"
},
{
"type":"created",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0x2::sui::SUI>",
"objectId":"0xf8049f908663106d14a7cdafa138f9d6201a242bd5705230e44249f785be4f37",
"version":"409729492",
"digest":"EkhTrd6U9gffq6bEBjAPKn999zCZnjG4EWGdWmZArmKT"
},
{
"type":"deleted",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"objectType":"0x2::coin::Coin<0x2::sui::SUI>",
"objectId":"0x2946df189f3251b6738e9807f6e22a64638b96a3945eb56c2a570c54068b4ba1",
"version":"409729492"
}
],
"confirmedLocalExecution":false
}