Skip to content

Commit 3b3fbe3

Browse files
authored
Merge branch 'main' into nialexsan/incrementfi-mock
2 parents 824139a + df6f03c commit 3b3fbe3

20 files changed

Lines changed: 673 additions & 0 deletions

.github/workflows/punchswap.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: KittyPunch tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
tests:
13+
name: KittyPunch Tests
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GH_PAT }}
19+
submodules: "recursive"
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: "1.23.x"
23+
cache: true
24+
cache-dependency-path: |
25+
**/go.sum
26+
- name: Install Flow CLI
27+
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v2.2.17
28+
- name: Flow CLI Version
29+
run: flow version
30+
- name: Update PATH
31+
run: echo "/root/.local/bin" >> $GITHUB_PATH
32+
- name: Run emulator
33+
run: ./local/run_emulator.sh
34+
- name: Create wallets
35+
run: ./local/setup_wallets.sh
36+
- name: Run EVM gateway
37+
run: ./local/run_evm_gateway.sh
38+
- name: Install Foundry
39+
uses: foundry-rs/foundry-toolchain@v1
40+
- name: Install Flow deps
41+
run: flow deps install
42+
- name: Setup PunchSwap
43+
run: ./local/punchswap/setup_punchswap.sh
44+
- name: Run e2e script
45+
run: ./local/punchswap/e2e_punchswap.sh
46+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
# flow
33
*.pkey
4+
!local/mock-incrementfi.pkey
5+
!local/emulator-account.pkey
6+
!local/evm-gateway.pkey
7+
!local/test-user.pkey
48
imports
59
coverage.lcov
610
coverage.json

.gitmodules

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
[submodule "lib/DeFiActions"]
66
path = lib/DeFiActions
77
url = git@github.com:onflow/DeFiActions.git
8+
branch = nialexsan/univ3
9+
[submodule "lib/flow-evm-gateway"]
10+
path = lib/flow-evm-gateway
11+
url = git@github.com:onflow/flow-evm-gateway.git
12+
[submodule "solidity/lib/punch-swap-v3-contracts"]
13+
path = solidity/lib/punch-swap-v3-contracts
14+
url = git@github.com:Kitty-Punch/punch-swap-v3-contracts.git
15+
[submodule "solidity/lib/forge-std"]
16+
path = solidity/lib/forge-std
17+
url = https://github.com/foundry-rs/forge-std
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
transaction {
2+
prepare(signer: auth(AddKey) &Account) {
3+
let firstKey = signer.keys.get(keyIndex: 0)!
4+
let range: InclusiveRange<Int> = InclusiveRange(1, 100, step: 1)
5+
for element in range {
6+
signer.keys.add(
7+
publicKey: firstKey.publicKey,
8+
hashAlgorithm: HashAlgorithm.SHA3_256,
9+
weight: 1000.0
10+
)
11+
}
12+
}
13+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import "FlowStorageFees"
2+
import "FungibleToken"
3+
import "FlowToken"
4+
5+
import "EVM"
6+
7+
// Transfers $FLOW from the signer's account to the recipient's address, determining the target VM based on the format
8+
// of the recipient's hex address. Note that the sender's funds are sourced by default from the target VM, pulling any
9+
// difference from the alternate VM if available. e.g. Transfers to Flow addresses will first attempt to withdraw from
10+
// the signer's Flow vault, pulling any remaining funds from the signer's EVM account if available. Transfers to EVM
11+
// addresses will first attempt to withdraw from the signer's EVM account, pulling any remaining funds from the signer's
12+
// Flow vault if available. If the signer's balance across both VMs is insufficient, the transaction will revert.
13+
///
14+
/// @param addressString: The recipient's address in hex format - this should be either an EVM address or a Flow address
15+
/// @param amount: The amount of $FLOW to transfer as a UFix64 value
16+
///
17+
transaction(addressString: String, amount: UFix64) {
18+
19+
let sentVault: @FlowToken.Vault
20+
let evmRecipient: EVM.EVMAddress?
21+
22+
prepare(signer: auth(BorrowValue, SaveValue) &Account) {
23+
// Reference signer's COA if one exists
24+
let coa = signer.storage.borrow<auth(EVM.Withdraw) &EVM.CadenceOwnedAccount>(from: /storage/evm)
25+
26+
// Reference signer's FlowToken Vault
27+
let sourceVault = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
28+
?? panic("Could not borrow signer's FlowToken.Vault")
29+
// Ensure we don't withdraw more than required for storage
30+
let cadenceBalance = FlowStorageFees.defaultTokenAvailableBalance(signer.address)
31+
32+
// Define optional recipients for both VMs
33+
self.evmRecipient = EVM.addressFromString(addressString)
34+
// Validate exactly one target address is assigned
35+
if self.evmRecipient == nil {
36+
panic("Malformed recipient address - not assignable as either Cadence or EVM address")
37+
}
38+
39+
// Create empty FLOW vault to capture funds
40+
self.sentVault <- FlowToken.createEmptyVault(vaultType: Type<@FlowToken.Vault>())
41+
42+
// Check signer's balance can cover the amount
43+
if coa != nil {
44+
// Determine the amount to withdraw from the signer's EVM account
45+
let balance = coa!.balance()
46+
let withdrawAmount = amount < balance.inFLOW() ? amount : balance.inFLOW()
47+
balance.setFLOW(flow: withdrawAmount)
48+
49+
// Withdraw funds from EVM to the sentVault
50+
self.sentVault.deposit(from: <-coa!.withdraw(balance: balance))
51+
}
52+
if amount > self.sentVault.balance {
53+
// Insufficient amount withdrawn from EVM, check signer's Flow balance
54+
let difference = amount - self.sentVault.balance
55+
if difference > cadenceBalance {
56+
panic("Insufficient balance across Flow and EVM accounts")
57+
}
58+
// Withdraw from the signer's Cadence Vault and deposit to sentVault
59+
self.sentVault.deposit(from: <-sourceVault.withdraw(amount: difference))
60+
}
61+
}
62+
63+
pre {
64+
self.sentVault.balance == amount: "Attempting to send an incorrect amount of $FLOW"
65+
}
66+
67+
execute {
68+
// Otherwise, complete EVM transfer
69+
self.evmRecipient!.deposit(from: <-self.sentVault)
70+
}
71+
}

flow.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@
132132
"testnet": "8c5303eaa26202d6"
133133
}
134134
},
135+
"FlowStorageFees": {
136+
"source": "mainnet://e467b9dd11fa00df.FlowStorageFees",
137+
"hash": "e38d8a95f6518b8ff46ce57dfa37b4b850b3638f33d16333096bc625b6d9b51a",
138+
"aliases": {
139+
"emulator": "f8d6e0586b0a20c7",
140+
"mainnet": "e467b9dd11fa00df",
141+
"testnet": "8c5303eaa26202d6"
142+
}
143+
},
135144
"FlowToken": {
136145
"source": "mainnet://1654653399040a61.FlowToken",
137146
"hash": "cefb25fd19d9fc80ce02896267eb6157a6b0df7b1935caa8641421fe34c0e67a",
@@ -257,6 +266,13 @@
257266
"location": "local/emulator-account.pkey"
258267
}
259268
},
269+
"evm-gateway": {
270+
"address": "e03daebed8ca0615",
271+
"key": {
272+
"type": "file",
273+
"location": "local/evm-gateway.pkey"
274+
}
275+
},
260276
"mock-incrementfi": {
261277
"address": "f3fcd2c1a78f5eee",
262278
"key": {
@@ -294,6 +310,7 @@
294310
"DeFiActionsMathUtils",
295311
"DeFiActionsUtils",
296312
"DeFiActions",
313+
"FlowStorageFees",
297314
"FungibleTokenConnectors",
298315
"SwapConnectors",
299316
{

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[profile.default]
2+
src = "./solidity/src"
3+
out = "./solidity/out"
4+
libs = ["./solidity/lib"]
5+
script = "./solidity/script"
6+
test = "./solidity/test"
7+
8+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

lib/flow-evm-gateway

Submodule flow-evm-gateway added at ea7b50d

local/evm-gateway.pkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7549ce91aa82b6b42b060df5ab60d1246ae61e83177b5adb81c697e41d9e587a

local/evm-gateway.pubkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1def7075711bb5d1d1b848a775f3308f0e2e8f4067a4a3a1bdfe71f5c5d194276698bf9912d514ee0d9f745a200a1860993538dba23d4b9b6d3c9eb6213d7ca3

0 commit comments

Comments
 (0)