TransactionSEALED

▫█□◆░□░╱●$╱□▓◆○█~◇^!◆◆◇%▪▓@◇▫~◇○#?╱▓◆?▓◆*╲^◇╱╱@█□**^○#^█●^*■!▪▓#

Transaction ID

Timestamp

Sep 05, 2024, 12:47:02 PM UTC
1y ago

Block Height

86,041,824

Computation

0

Proposerseq:398 key:0

Authorizers

1

Transaction Summary

Transaction

Script Arguments

0token0KeyString
A.921ea449dffec68a.FlovatarDustToken
1token1KeyString
A.1654653399040a61.FlowToken
2lpTokenAmountUFix64
432.40218596
3token0OutMinUFix64
9362.28728309
4token1OutMinUFix64
20.76563280
5deadlineUFix64
1725715323.00000000
6token0VaultPathStoragePath
storage/FlovatarDustTokenVault
7token1VaultPathStoragePath
storage/flowTokenVault
8stableModeBool
false

Cadence Script

1import FungibleToken from 0xf233dcee88fe0abe
2import SwapFactory from 0xb063c16cac85dbd1
3import StableSwapFactory from 0xb063c16cac85dbd1
4import SwapInterfaces from 0xb78ef7afa52ff906
5import SwapConfig from 0xb78ef7afa52ff906
6import SwapError from 0xb78ef7afa52ff906
7
8transaction(
9    token0Key: String,
10    token1Key: String,
11    lpTokenAmount: UFix64,
12    token0OutMin: UFix64,
13    token1OutMin: UFix64,
14    deadline: UFix64,
15    token0VaultPath: StoragePath,
16    token1VaultPath: StoragePath,
17    stableMode: Bool
18) {
19    prepare(userAccount: auth(BorrowValue) &Account) {
20        assert(deadline >= getCurrentBlock().timestamp, message:
21            SwapError.ErrorEncode(
22                msg: "RemoveLiquidity: expired ".concat(deadline.toString()).concat(" < ").concat(getCurrentBlock().timestamp.toString()),
23                err: SwapError.ErrorCode.EXPIRED
24            )
25        )
26        let pairAddr = stableMode ?
27            StableSwapFactory.getPairAddress(token0Key: token0Key, token1Key: token1Key) ?? panic("AddLiquidity: nonexistent stable pair ".concat(token0Key).concat(" <-> ").concat(token1Key).concat(", create stable pair first"))
28            :
29            SwapFactory.getPairAddress(token0Key: token0Key, token1Key: token1Key) ?? panic("AddLiquidity: nonexistent pair ".concat(token0Key).concat(" <-> ").concat(token1Key).concat(", create pair first"))
30        
31        let lpTokenCollectionRef = userAccount.storage.borrow<auth(FungibleToken.Withdraw) &SwapFactory.LpTokenCollection>(from: SwapConfig.LpTokenCollectionStoragePath)
32            ?? panic("RemoveLiquidity: cannot borrow reference to LpTokenCollection")
33
34        let lpTokenRemove <- lpTokenCollectionRef.withdraw(pairAddr: pairAddr, amount: lpTokenAmount)
35        let tokens <- getAccount(pairAddr).capabilities.borrow<&{SwapInterfaces.PairPublic}>(SwapConfig.PairPublicPath)!.removeLiquidity(lpTokenVault: <-lpTokenRemove)
36        let token0Vault <- tokens[0].withdraw(amount: tokens[0].balance)
37        let token1Vault <- tokens[1].withdraw(amount: tokens[1].balance)
38        destroy tokens
39
40        assert(token0Vault.balance >= token0OutMin && token1Vault.balance >= token1OutMin, message:
41            SwapError.ErrorEncode(
42                msg: "RemoveLiquidity: INSUFFICIENT_REMOVE_LIQUIDITY_OUT_AMOUNT",
43                err: SwapError.ErrorCode.SLIPPAGE_OFFSET_TOO_LARGE
44            )
45        )
46
47        /// Here does not detect whether the local receiver vault exsit.
48        let localVault0Ref = userAccount.storage.borrow<&{FungibleToken.Vault}>(from: token0VaultPath)!
49        let localVault1Ref = userAccount.storage.borrow<&{FungibleToken.Vault}>(from: token1VaultPath)!
50        if token0Vault.isInstance(localVault0Ref.getType()) {
51            localVault0Ref.deposit(from: <-token0Vault)
52            localVault1Ref.deposit(from: <-token1Vault)
53        } else {
54            localVault0Ref.deposit(from: <-token1Vault)
55            localVault1Ref.deposit(from: <-token0Vault)
56        }
57    }
58}