Skip to content

Commit 12290b2

Browse files
committed
Replace COA.call with COA.callWithSigAndArgs for reduced computation cost
1 parent c6bace8 commit 12290b2

11 files changed

+291
-364
lines changed

cadence/contracts/FlowYieldVaultsEVM.cdc

Lines changed: 181 additions & 246 deletions
Large diffs are not rendered by default.

cadence/scripts/admin/get_allowlist_status.cdc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,39 @@ access(all) fun main(contractAddress: String, addressToCheck: String): Allowlist
2626
let fromAddress = EVM.addressFromString("0x0000000000000000000000000000000000000001")
2727

2828
// Read allowlistEnabled
29-
let enabledCalldata = EVM.encodeABIWithSignature("allowlistEnabled()", [])
30-
let enabledResult = EVM.dryCall(
29+
let enabledResult = EVM.dryCallWithSigAndArgs(
3130
from: fromAddress,
3231
to: evmContractAddress,
33-
data: enabledCalldata,
32+
signature: "allowlistEnabled()",
33+
args: [],
3434
gasLimit: 100_000,
35-
value: EVM.Balance(attoflow: 0)
35+
value: EVM.Balance(attoflow: 0),
36+
resultTypes: [Type<Bool>()]
3637
)
3738

3839
var enabled = false
3940
if enabledResult.status == EVM.Status.successful {
40-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: enabledResult.data)
41-
enabled = decoded[0] as! Bool
41+
assert(enabledResult.results.length == 1, message: "Invalid response from allowlistEnabled()")
42+
enabled = enabledResult.results[0] as! Bool
4243
}
4344

4445
// Check if address is allowlisted (if provided)
4546
var isAllowlisted = false
4647
if addressToCheck.length > 0 {
4748
let checkAddress = EVM.addressFromString(addressToCheck)
48-
let allowlistedCalldata = EVM.encodeABIWithSignature("allowlisted(address)", [checkAddress])
49-
let allowlistedResult = EVM.dryCall(
49+
let allowlistedResult = EVM.dryCallWithSigAndArgs(
5050
from: fromAddress,
5151
to: evmContractAddress,
52-
data: allowlistedCalldata,
52+
signature: "allowlisted(address)",
53+
args: [checkAddress],
5354
gasLimit: 100_000,
54-
value: EVM.Balance(attoflow: 0)
55+
value: EVM.Balance(attoflow: 0),
56+
resultTypes: [Type<Bool>()]
5557
)
5658

5759
if allowlistedResult.status == EVM.Status.successful {
58-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: allowlistedResult.data)
59-
isAllowlisted = decoded[0] as! Bool
60+
assert(allowlistedResult.results.length == 1, message: "Invalid response from allowlisted()")
61+
isAllowlisted = allowlistedResult.results[0] as! Bool
6062
}
6163
}
6264

cadence/scripts/admin/get_blocklist_status.cdc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,39 @@ access(all) fun main(contractAddress: String, addressToCheck: String): Blocklist
2626
let fromAddress = EVM.addressFromString("0x0000000000000000000000000000000000000001")
2727

2828
// Read blocklistEnabled
29-
let enabledCalldata = EVM.encodeABIWithSignature("blocklistEnabled()", [])
30-
let enabledResult = EVM.dryCall(
29+
let enabledResult = EVM.dryCallWithSigAndArgs(
3130
from: fromAddress,
3231
to: evmContractAddress,
33-
data: enabledCalldata,
32+
signature: "blocklistEnabled()",
33+
args: [],
3434
gasLimit: 100_000,
35-
value: EVM.Balance(attoflow: 0)
35+
value: EVM.Balance(attoflow: 0),
36+
resultTypes: [Type<Bool>()]
3637
)
3738

3839
var enabled = false
3940
if enabledResult.status == EVM.Status.successful {
40-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: enabledResult.data)
41-
enabled = decoded[0] as! Bool
41+
assert(enabledResult.results.length == 1, message: "Invalid response from blocklistEnabled()")
42+
enabled = enabledResult.results[0] as! Bool
4243
}
4344

4445
// Check if address is blocklisted (if provided)
4546
var isBlocklisted = false
4647
if addressToCheck.length > 0 {
4748
let checkAddress = EVM.addressFromString(addressToCheck)
48-
let blocklistedCalldata = EVM.encodeABIWithSignature("blocklisted(address)", [checkAddress])
49-
let blocklistedResult = EVM.dryCall(
49+
let blocklistedResult = EVM.dryCallWithSigAndArgs(
5050
from: fromAddress,
5151
to: evmContractAddress,
52-
data: blocklistedCalldata,
52+
signature: "blocklisted(address)",
53+
args: [checkAddress],
5354
gasLimit: 100_000,
54-
value: EVM.Balance(attoflow: 0)
55+
value: EVM.Balance(attoflow: 0),
56+
resultTypes: [Type<Bool>()]
5557
)
5658

5759
if blocklistedResult.status == EVM.Status.successful {
58-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: blocklistedResult.data)
59-
isBlocklisted = decoded[0] as! Bool
60+
assert(blocklistedResult.results.length == 1, message: "Invalid response from blocklisted()")
61+
isBlocklisted = blocklistedResult.results[0] as! Bool
6062
}
6163
}
6264

cadence/scripts/admin/get_evm_contract_config.cdc

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,77 +39,82 @@ access(all) fun main(contractAddress: String): EVMContractConfig {
3939

4040
// Read authorizedCOA
4141
var authorizedCOA = ""
42-
let coaCalldata = EVM.encodeABIWithSignature("authorizedCOA()", [])
43-
let coaResult = EVM.dryCall(
42+
let coaResult = EVM.dryCallWithSigAndArgs(
4443
from: fromAddress,
4544
to: evmContractAddress,
46-
data: coaCalldata,
45+
signature: "authorizedCOA()",
46+
args: [],
4747
gasLimit: 100_000,
48-
value: EVM.Balance(attoflow: 0)
48+
value: EVM.Balance(attoflow: 0),
49+
resultTypes: [Type<EVM.EVMAddress>()]
4950
)
5051
if coaResult.status == EVM.Status.successful {
51-
let decoded = EVM.decodeABI(types: [Type<EVM.EVMAddress>()], data: coaResult.data)
52-
authorizedCOA = (decoded[0] as! EVM.EVMAddress).toString()
52+
assert(coaResult.results.length == 1, message: "Invalid response from authorizedCOA()")
53+
authorizedCOA = (coaResult.results[0] as! EVM.EVMAddress).toString()
5354
}
5455

5556
// Read allowlistEnabled
5657
var allowlistEnabled = false
57-
let allowlistCalldata = EVM.encodeABIWithSignature("allowlistEnabled()", [])
58-
let allowlistResult = EVM.dryCall(
58+
let allowlistResult = EVM.dryCallWithSigAndArgs(
5959
from: fromAddress,
6060
to: evmContractAddress,
61-
data: allowlistCalldata,
61+
signature: "allowlistEnabled()",
62+
args: [],
6263
gasLimit: 100_000,
63-
value: EVM.Balance(attoflow: 0)
64+
value: EVM.Balance(attoflow: 0),
65+
resultTypes: [Type<Bool>()]
6466
)
6567
if allowlistResult.status == EVM.Status.successful {
66-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: allowlistResult.data)
67-
allowlistEnabled = decoded[0] as! Bool
68+
assert(allowlistResult.results.length == 1, message: "Invalid response from allowlistEnabled()")
69+
allowlistEnabled = allowlistResult.results[0] as! Bool
6870
}
6971

7072
// Read blocklistEnabled
7173
var blocklistEnabled = false
72-
let blocklistCalldata = EVM.encodeABIWithSignature("blocklistEnabled()", [])
73-
let blocklistResult = EVM.dryCall(
74+
let blocklistResult = EVM.dryCallWithSigAndArgs(
7475
from: fromAddress,
7576
to: evmContractAddress,
76-
data: blocklistCalldata,
77+
signature: "blocklistEnabled()",
78+
args: [],
7779
gasLimit: 100_000,
78-
value: EVM.Balance(attoflow: 0)
80+
value: EVM.Balance(attoflow: 0),
81+
resultTypes: [Type<Bool>()]
7982
)
8083
if blocklistResult.status == EVM.Status.successful {
81-
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: blocklistResult.data)
82-
blocklistEnabled = decoded[0] as! Bool
84+
assert(blocklistResult.results.length == 1, message: "Invalid response from blocklistEnabled()")
85+
blocklistEnabled = blocklistResult.results[0] as! Bool
8386
}
8487

8588
// Read maxPendingRequestsPerUser
8689
var maxPendingRequestsPerUser: UInt256 = 0
87-
let maxCalldata = EVM.encodeABIWithSignature("maxPendingRequestsPerUser()", [])
88-
let maxResult = EVM.dryCall(
90+
let maxResult = EVM.dryCallWithSigAndArgs(
8991
from: fromAddress,
9092
to: evmContractAddress,
91-
data: maxCalldata,
93+
signature: "maxPendingRequestsPerUser()",
94+
args: [],
9295
gasLimit: 100_000,
93-
value: EVM.Balance(attoflow: 0)
96+
value: EVM.Balance(attoflow: 0),
97+
resultTypes: [Type<UInt256>()]
9498
)
9599
if maxResult.status == EVM.Status.successful {
96-
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: maxResult.data)
97-
maxPendingRequestsPerUser = decoded[0] as! UInt256
100+
assert(maxResult.results.length == 1, message: "Invalid response from maxPendingRequestsPerUser()")
101+
maxPendingRequestsPerUser = maxResult.results[0] as! UInt256
98102
}
99103

100104
// Read getPendingRequestCount
101105
var pendingRequestCount: UInt256 = 0
102-
let countCalldata = EVM.encodeABIWithSignature("getPendingRequestCount()", [])
103-
let countResult = EVM.dryCall(
106+
let countResult = EVM.dryCallWithSigAndArgs(
104107
from: fromAddress,
105108
to: evmContractAddress,
106-
data: countCalldata,
109+
signature: "getPendingRequestCount()",
110+
args: [],
107111
gasLimit: 100_000,
108-
value: EVM.Balance(attoflow: 0)
112+
value: EVM.Balance(attoflow: 0),
113+
resultTypes: [Type<UInt256>()]
109114
)
110115
if countResult.status == EVM.Status.successful {
111-
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: countResult.data)
112-
pendingRequestCount = decoded[0] as! UInt256
116+
assert(countResult.results.length == 1, message: "Invalid response from getPendingRequestCount()")
117+
pendingRequestCount = countResult.results[0] as! UInt256
113118
}
114119

115120
return EVMContractConfig(

cadence/scripts/admin/get_evm_yieldvaults_for_user.cdc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ access(all) fun main(contractAddress: String, userAddress: String): [UInt64] {
1515
let evmUserAddress = EVM.addressFromString(userAddress)
1616

1717
// Read getYieldVaultIdsForUser(address)
18-
let calldata = EVM.encodeABIWithSignature(
19-
"getYieldVaultIdsForUser(address)",
20-
[evmUserAddress]
21-
)
22-
let result = EVM.dryCall(
18+
let result = EVM.dryCallWithSigAndArgs(
2319
from: fromAddress,
2420
to: evmContractAddress,
25-
data: calldata,
21+
signature: "getYieldVaultIdsForUser(address)",
22+
args: [evmUserAddress],
2623
gasLimit: 500_000,
27-
value: EVM.Balance(attoflow: 0)
24+
value: EVM.Balance(attoflow: 0),
25+
resultTypes: [Type<[UInt64]>()]
2826
)
2927

3028
if result.status == EVM.Status.successful {
31-
let decoded = EVM.decodeABI(types: [Type<[UInt64]>()], data: result.data)
32-
return decoded[0] as! [UInt64]
29+
assert(result.results.length == 1, message: "Invalid response from getYieldVaultIdsForUser()")
30+
return result.results[0] as! [UInt64]
3331
}
3432

3533
return []

cadence/scripts/admin/get_token_config.cdc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,25 @@ access(all) fun main(contractAddress: String, tokenAddress: String): TokenConfig
2929
let evmTokenAddress = EVM.addressFromString(tokenAddress)
3030

3131
// Read allowedTokens(address)
32-
let calldata = EVM.encodeABIWithSignature("allowedTokens(address)", [evmTokenAddress])
33-
let result = EVM.dryCall(
32+
let result = EVM.dryCallWithSigAndArgs(
3433
from: fromAddress,
3534
to: evmContractAddress,
36-
data: calldata,
35+
signature: "allowedTokens(address)",
36+
args: [evmTokenAddress],
3737
gasLimit: 100_000,
38-
value: EVM.Balance(attoflow: 0)
38+
value: EVM.Balance(attoflow: 0),
39+
resultTypes: [Type<Bool>(), Type<UInt256>(), Type<Bool>()]
3940
)
4041

4142
var isSupported = false
4243
var minimumBalance: UInt256 = 0
4344
var isNative = false
4445

4546
if result.status == EVM.Status.successful {
46-
let decoded = EVM.decodeABI(
47-
types: [Type<Bool>(), Type<UInt256>(), Type<Bool>()],
48-
data: result.data
49-
)
50-
isSupported = decoded[0] as! Bool
51-
minimumBalance = decoded[1] as! UInt256
52-
isNative = decoded[2] as! Bool
47+
assert(result.results.length == 3, message: "Invalid response from allowedTokens()")
48+
isSupported = result.results[0] as! Bool
49+
minimumBalance = result.results[1] as! UInt256
50+
isNative = result.results[2] as! Bool
5351
}
5452

5553
return TokenConfig(

cadence/scripts/admin/get_user_pending_balance.cdc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@ access(all) fun main(contractAddress: String, userAddress: String, tokenAddress:
1717
let evmTokenAddress = EVM.addressFromString(tokenAddress)
1818

1919
// Read getUserPendingBalance(address, address)
20-
let calldata = EVM.encodeABIWithSignature(
21-
"getUserPendingBalance(address,address)",
22-
[evmUserAddress, evmTokenAddress]
23-
)
24-
let result = EVM.dryCall(
20+
let result = EVM.dryCallWithSigAndArgs(
2521
from: fromAddress,
2622
to: evmContractAddress,
27-
data: calldata,
23+
signature: "getUserPendingBalance(address,address)",
24+
args: [evmUserAddress, evmTokenAddress],
2825
gasLimit: 100_000,
29-
value: EVM.Balance(attoflow: 0)
26+
value: EVM.Balance(attoflow: 0),
27+
resultTypes: [Type<UInt256>()]
3028
)
3129

3230
if result.status == EVM.Status.successful {
33-
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: result.data)
34-
return decoded[0] as! UInt256
31+
assert(result.results.length == 1, message: "Invalid response from getUserPendingBalance()")
32+
return result.results[0] as! UInt256
3533
}
3634

3735
return 0

cadence/scripts/admin/get_user_pending_request_count.cdc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ access(all) fun main(contractAddress: String, userAddress: String): UInt256 {
1515
let evmUserAddress = EVM.addressFromString(userAddress)
1616

1717
// Read getUserPendingRequestCount(address)
18-
let calldata = EVM.encodeABIWithSignature(
19-
"getUserPendingRequestCount(address)",
20-
[evmUserAddress]
21-
)
22-
let result = EVM.dryCall(
18+
let result = EVM.dryCallWithSigAndArgs(
2319
from: fromAddress,
2420
to: evmContractAddress,
25-
data: calldata,
21+
signature: "getUserPendingRequestCount(address)",
22+
args: [evmUserAddress],
2623
gasLimit: 100_000,
27-
value: EVM.Balance(attoflow: 0)
24+
value: EVM.Balance(attoflow: 0),
25+
resultTypes: [Type<UInt256>()]
2826
)
2927

3028
if result.status == EVM.Status.successful {
31-
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: result.data)
32-
return decoded[0] as! UInt256
29+
assert(result.results.length == 1, message: "Invalid response from getUserPendingRequestCount()")
30+
return result.results[0] as! UInt256
3331
}
3432

3533
return 0

cadence/transactions/admin/accept_ownership.cdc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ transaction(contractAddress: String) {
1818
execute {
1919
let evmAddress = EVM.addressFromString(contractAddress)
2020

21-
let calldata = EVM.encodeABIWithSignature(
22-
"acceptOwnership()",
23-
[]
24-
)
25-
26-
let result = self.coa.call(
21+
let result = self.coa.callWithSigAndArgs(
2722
to: evmAddress,
28-
data: calldata,
23+
signature: "acceptOwnership()",
24+
args: [],
2925
gasLimit: 100_000,
30-
value: EVM.Balance(attoflow: 0)
26+
value: EVM.Balance(attoflow: 0),
27+
resultTypes: nil
3128
)
3229

3330
assert(result.status == EVM.Status.successful, message: "acceptOwnership failed")

cadence/transactions/approve_erc20_from_coa.cdc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ transaction(tokenAddressHex: String, spenderAddressHex: String, amount: UInt256)
2323
let tokenAddress = EVM.addressFromString(tokenAddressHex)
2424
let spenderAddress = EVM.addressFromString(spenderAddressHex)
2525

26-
// Encode approve(address,uint256) call using EVM.encodeABIWithSignature
27-
let calldata = EVM.encodeABIWithSignature(
28-
"approve(address,uint256)",
29-
[spenderAddress, amount]
30-
)
31-
32-
let result = self.coa.call(
26+
// Call the function approve(address,uint256)
27+
let result = self.coa.callWithSigAndArgs(
3328
to: tokenAddress,
34-
data: calldata,
29+
signature: "approve(address,uint256)",
30+
args: [spenderAddress, amount],
3531
gasLimit: 100_000,
36-
value: EVM.Balance(attoflow: 0)
32+
value: EVM.Balance(attoflow: 0),
33+
resultTypes: nil
3734
)
3835

3936
assert(

0 commit comments

Comments
 (0)