Tinyman Docs
Search…
Swap
Swap one asset (ASA or Algo) for another with the Pool.

Transaction Group

0. Pay - pay fees in Algo from Swapper to Pool
  • fees to cover Tx 1,2
  • Signed by Swapper
1
{
2
"txn": {
3
"type": "pay",
4
"rcv": "{POOL_ADDRESS}",
5
"snd": "{SWAPPER_ADDRESS",
6
"amt": 2000,
7
"fee": 1000,
8
...
9
},
10
"sig": "{SWAPPER_SIG}",
11
}
Copied!
  1. 1.
    App Call - NoOp call to Validator App with args ['swap', (fixed-input) or 'fo' (fixed-output)], with Swapper account
    • Signed by Pool LogicSig
    • Argument 1 'fi' specifies that the input (sell) is fixed but the output may vary with slippage
    • Argument 1 'fo' specifies that the output (buy) is fixed but the input may vary with slippage
1
{
2
"txn": {
3
"type": "appl",
4
"snd": "{POOL_ADDRESS}",
5
"apid": {VALIDATOR_APP_ID},
6
"apan": 0, // OnComplete: NoOp
7
"apaa": ['c3dhcA==', 'Zmk=' or 'Zm8='], // ['swap', 'fi' (fixed-input) or 'fo' (fixed-output)]
8
"apat": [{SWAPPER_ADDRESS}],
9
"fee": 1000,
10
...
11
},
12
"lsig": "{POOL_LOGICSIG}",
13
}
Copied!
2. (a) AssetTransfer - Transfer of sell asset from Swapper to Pool
  • If sell asset is an ASA
  • Signed by Swapper
1
{
2
"txn": {
3
"type": "axfer",
4
"arcv": "{POOL_ADDRESS}",
5
"snd": "{SWAPPER_ADDRESS}",
6
"xaid": {SELL_ASSET_ID},
7
"aamt": {SELL_ASSET_AMOUNT},
8
"fee": 1000,
9
...
10
},
11
"sig": "{SWAPPER_SIG}",
12
}
Copied!
2. (b) Pay - Transfer of Algo from Swapper to Pool
  • If sell asset is Algo
  • Signed by Swapper
1
{
2
"txn": {
3
"type": "pay",
4
"rcv": "{POOL_ADDRESS}",
5
"snd": "{SWAPPER_ADDRESS}",
6
"amt": {SELL_ASSET_AMOUNT},
7
"fee": 1000,
8
...
9
},
10
"sig": "{SWAPPER_SIG}",
11
}
Copied!
3. (a) AssetTransfer - Transfer of buy asset from Pool to Swapper
  • If buy asset is an ASA
  • Signed by Pool LogicSig
1
{
2
"txn": {
3
"type": "axfer",
4
"arcv": "{SWAPPER_ADDRESS}",
5
"snd": "{POOL_ADDRESS}",
6
"xaid": {BUY_ASSET_ID},
7
"aamt": {BUY_ASSET_AMOUNT},
8
"fee": 1000,
9
...
10
},
11
"lsig": "{POOL_LOGICSIG}",
12
}
Copied!
3. (b) Pay - Transfer of buy asset from Pool to Swapper
  • If buy asset is Algo
  • Signed by Pool LogicSig
1
{
2
"txn": {
3
"type": "pay",
4
"rcv": "{SWAPPER_ADDRESS}",
5
"snd": "{POOL_ADDRESS}",
6
"amt": {BUY_ASSET_AMOUNT},
7
"fee": 1000,
8
...
9
},
10
"lsig": "{POOL_LOGICSIG}",
11
}
Copied!

Validator App State Changes

Global State
None
Pool Account Local State
  • o{ASSET1_ID}: {int} // total outstanding unredeemed asset 1 amount
  • o{ASSET2_ID}: {int} // total outstanding unredeemed asset 2 amount
  • p: {int} // total unclaimed protocol fees amount
Swapper Account Local State
  • {POOL_ADDRESS}e{ASSET1_ID}: {int} // excess asset 1 amount available for redemption
  • {POOL_ADDRESS}e{ASSET2_ID}: {int} // excess asset 2 amount available for redemption
Last modified 9mo ago
Copy link