Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

implement a swap with ninja nitro #5

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

implement a swap with ninja nitro #5

wants to merge 4 commits into from

Conversation

geoknee
Copy link
Contributor

@geoknee geoknee commented Apr 12, 2021

the output on my machine is

➜  cross-chain git:(ninja-nitro) ✗ yarn go-ninja
yarn run v1.22.1
$ ts-node ./ninja-atomic-swap/happy-case.ts
ganache listening on port 9002...
ganache listening on port 9001...
> I have 10000000000 tokens on the left chain
> I have 0 tokens on the right chain
< I have 0 tokens on the left chain
< I have 10000000000 tokens on the right chain
> I propose a hashlocked payment, sending PreFund0 for chain 0x42
< Sure thing. Your channel looks good. Sending PreFund1 for chain 0x42
Gas used for fundChannel: 51139
[
  { count: 2, gas: 25000, op: 'SSTORE' },
  { count: 1, gas: 1756, op: 'LOG3' },
  { count: 2, gas: 1600, op: 'SLOAD' },
  '...'
]
> sent funds to contract on chain 66, spent 51139 gas
> I have made my deposit, and send PostFund2 for chain 0x42
< I see your deposit and send PostFund3 for chain 0x42
< I propose a hashlocked payment, sending PreFund0 for chain 0x63
> Sure thing. Your channel looks good. Sending PreFund1 for chain 0x63
Gas used for fundChannel: 51139
[
  { count: 2, gas: 25000, op: 'SSTORE' },
  { count: 1, gas: 1756, op: 'LOG3' },
  { count: 2, gas: 1600, op: 'SLOAD' },
  '...'
]
< sent funds to contract on chain 99, spent 51139 gas
< I have made my deposit, and send PostFund2 for chain 0x63
> I see your deposit and send PostFund3 for chain 0x63
< I verified your unlock was valid; Here's a final state to help you withdraw on chain 0x63
> Countersigning...
> I verified your unlock was valid; Here's a final state to help you withdraw on chain 0x42
< Countersigning...
Gas used for createAndPayout: 115634
Gas used for createAndPayout: 115646
[
  { count: 1, gas: 33395, op: 'CREATE2' },
  { count: 4, gas: 26600, op: 'SSTORE' },
  { count: 3, gas: 9113, op: 'STATICCALL' },
  { count: 7, gas: 5600, op: 'SLOAD' },
  { count: 3, gas: 4491, op: 'CALL' },
  { count: 5, gas: 4213, op: 'RETURN' },
  { count: 1, gas: 3863, op: 'SELFDESTRUCT' },
  { count: 2, gas: 3512, op: 'LOG3' },
  { count: 314, gas: 3140, op: 'JUMPI' },
  { count: 4, gas: 2800, op: 'EXTCODESIZE' },
  { count: 343, gas: 2744, op: 'JUMP' },
  { count: 877, gas: 2631, op: 'PUSH1' },
  { count: 666, gas: 1998, op: 'PUSH2' },
  { count: 1, gas: 1837, op: 'DELEGATECALL' },
  { count: 558, gas: 1674, op: 'ADD' },
  { count: 537, gas: 1611, op: 'DUP2' },
  { count: 1, gas: 1381, op: 'LOG2' },
  { count: 248, gas: 1329, op: 'MSTORE' },
  { count: 464, gas: 928, op: 'POP' },
  { count: 292, gas: 876, op: 'SWAP1' },
  { count: 266, gas: 798, op: 'DUP3' },
  { count: 15, gas: 762, op: 'SHA3' },
  { count: 235, gas: 705, op: 'MLOAD' },
  { count: 227, gas: 681, op: 'DUP4' },
  { count: 225, gas: 675, op: 'ISZERO' },
  { count: 592, gas: 592, op: 'JUMPDEST' },
  { count: 192, gas: 576, op: 'DUP1' },
  { count: 4, gas: 474, op: 'CALLDATACOPY' },
  { count: 149, gas: 447, op: 'LT' },
  { count: 145, gas: 435, op: 'SWAP2' },
  { count: 132, gas: 396, op: 'DUP5' },
  { count: 122, gas: 366, op: 'SUB' },
  { count: 108, gas: 324, op: 'AND' },
  { count: 82, gas: 246, op: 'DUP6' },
  { count: 76, gas: 228, op: 'SHL' },
  { count: 76, gas: 228, op: 'SWAP3' },
  { count: 67, gas: 201, op: 'GT' },
  '...'
]
> Spent 115634 gas calling adjudicatorFactory.deployAndPayout, total 166773
[
  { count: 1, gas: 33395, op: 'CREATE2' },
  { count: 4, gas: 26600, op: 'SSTORE' },
  { count: 3, gas: 9113, op: 'STATICCALL' },
  { count: 7, gas: 5600, op: 'SLOAD' },
  { count: 3, gas: 4491, op: 'CALL' },
  { count: 5, gas: 4213, op: 'RETURN' },
  { count: 1, gas: 3863, op: 'SELFDESTRUCT' },
  { count: 2, gas: 3512, op: 'LOG3' },
  { count: 314, gas: 3140, op: 'JUMPI' },
  { count: 4, gas: 2800, op: 'EXTCODESIZE' },
  { count: 343, gas: 2744, op: 'JUMP' },
  { count: 877, gas: 2631, op: 'PUSH1' },
  { count: 666, gas: 1998, op: 'PUSH2' },
  { count: 1, gas: 1837, op: 'DELEGATECALL' },
  { count: 558, gas: 1674, op: 'ADD' },
  { count: 537, gas: 1611, op: 'DUP2' },
  { count: 1, gas: 1381, op: 'LOG2' },
  { count: 248, gas: 1329, op: 'MSTORE' },
  { count: 464, gas: 928, op: 'POP' },
  { count: 292, gas: 876, op: 'SWAP1' },
  { count: 266, gas: 798, op: 'DUP3' },
  { count: 15, gas: 762, op: 'SHA3' },
  { count: 235, gas: 705, op: 'MLOAD' },
  { count: 227, gas: 681, op: 'DUP4' },
  { count: 225, gas: 675, op: 'ISZERO' },
  { count: 592, gas: 592, op: 'JUMPDEST' },
  { count: 192, gas: 576, op: 'DUP1' },
  { count: 4, gas: 474, op: 'CALLDATACOPY' },
  { count: 149, gas: 447, op: 'LT' },
  { count: 145, gas: 435, op: 'SWAP2' },
  { count: 132, gas: 396, op: 'DUP5' },
  { count: 122, gas: 366, op: 'SUB' },
  { count: 108, gas: 324, op: 'AND' },
  { count: 82, gas: 246, op: 'DUP6' },
  { count: 76, gas: 228, op: 'SHL' },
  { count: 76, gas: 228, op: 'SWAP3' },
  { count: 67, gas: 201, op: 'GT' },
  '...'
]
< Spent 115646 gas calling adjudicatorFactory.deployAndPayout, total 166785
> I have 9999999998 tokens on the left chain
> I have 2 tokens on the right chain
< I have 2 tokens on the left chain
< I have 9999999998 tokens on the right chain
Total gas spent by all parties: 333558
✨  Done in 56.00s.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant