-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Gateway methods and Solana deposit (#179)
- Loading branch information
Showing
53 changed files
with
3,522 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ethers } from "ethers"; | ||
|
||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
import { ZetaChainClient } from "./client"; | ||
|
||
export const evmCall = async function ( | ||
this: ZetaChainClient, | ||
args: { | ||
callOnRevert: boolean; | ||
gasLimit: number; | ||
gasPrice: ethers.BigNumber; | ||
gatewayEvm: string; | ||
onRevertGasLimit: number; | ||
receiver: string; | ||
revertAddress: string; | ||
revertMessage: string; | ||
types: string; | ||
values: any[]; | ||
} | ||
) { | ||
const signer = this.signer; | ||
const { utils } = ethers; | ||
const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); | ||
|
||
const encodedParameters = utils.defaultAbiCoder.encode( | ||
JSON.parse(args.types), | ||
args.values | ||
); | ||
const tx = await gateway[ | ||
"call(address,bytes,(address,bool,address,bytes,uint256))" | ||
]( | ||
args.receiver, | ||
encodedParameters, | ||
{ | ||
abortAddress: "0x0000000000000000000000000000000000000000", | ||
callOnRevert: args.callOnRevert, | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
revertAddress: args.revertAddress, | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
}, | ||
{ | ||
gasLimit: args.gasLimit, | ||
gasPrice: args.gasPrice, | ||
} | ||
); | ||
|
||
return tx; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; | ||
import { ethers } from "ethers"; | ||
|
||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
import { ZetaChainClient } from "./client"; | ||
|
||
export const evmDeposit = async function ( | ||
this: ZetaChainClient, | ||
args: { | ||
amount: string; | ||
callOnRevert: boolean; | ||
erc20: string; | ||
gasLimit: number; | ||
gasPrice: ethers.BigNumber; | ||
gatewayEvm: string; | ||
onRevertGasLimit: number; | ||
receiver: string; | ||
revertAddress: string; | ||
revertMessage: string; | ||
} | ||
) { | ||
const signer = this.signer; | ||
const { utils } = ethers; | ||
const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); | ||
|
||
const revertOptions = { | ||
abortAddress: "0x0000000000000000000000000000000000000000", | ||
callOnRevert: args.callOnRevert, | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
revertAddress: args.revertAddress, | ||
// not used | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
}; | ||
|
||
const txOptions = { | ||
gasLimit: args.gasLimit, | ||
gasPrice: args.gasPrice, | ||
}; | ||
let tx; | ||
if (args.erc20) { | ||
const erc20Contract = new ethers.Contract( | ||
args.erc20, | ||
ERC20_ABI.abi, | ||
signer | ||
); | ||
const decimals = await erc20Contract.decimals(); | ||
const value = utils.parseUnits(args.amount, decimals); | ||
await erc20Contract.connect(signer).approve(args.gatewayEvm, value); | ||
const method = | ||
"deposit(address,uint256,address,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
value, | ||
args.erc20, | ||
revertOptions, | ||
txOptions | ||
); | ||
} else { | ||
const value = utils.parseEther(args.amount); | ||
const method = "deposit(address,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method](args.receiver, revertOptions, { | ||
...txOptions, | ||
value, | ||
}); | ||
} | ||
|
||
return tx; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; | ||
import { ethers } from "ethers"; | ||
|
||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
import { ZetaChainClient } from "./client"; | ||
|
||
export const evmDepositAndCall = async function ( | ||
this: ZetaChainClient, | ||
args: { | ||
amount: string; | ||
callOnRevert: boolean; | ||
erc20: string; | ||
gasLimit: number; | ||
gasPrice: ethers.BigNumber; | ||
gatewayEvm: string; | ||
onRevertGasLimit: number; | ||
receiver: string; | ||
revertAddress: string; | ||
revertMessage: string; | ||
types: string; | ||
values: any[]; | ||
} | ||
) { | ||
const signer = this.signer; | ||
const { utils } = ethers; | ||
const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); | ||
|
||
const revertOptions = { | ||
abortAddress: "0x0000000000000000000000000000000000000000", | ||
callOnRevert: args.callOnRevert, | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
revertAddress: args.revertAddress, | ||
// not used | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
}; | ||
|
||
const txOptions = { | ||
gasLimit: args.gasLimit, | ||
gasPrice: args.gasPrice, | ||
}; | ||
|
||
const encodedParameters = utils.defaultAbiCoder.encode( | ||
JSON.parse(args.types), | ||
args.values | ||
); | ||
let tx; | ||
if (args.erc20) { | ||
const erc20Contract = new ethers.Contract( | ||
args.erc20, | ||
ERC20_ABI.abi, | ||
signer | ||
); | ||
const decimals = await erc20Contract.decimals(); | ||
const value = utils.parseUnits(args.amount, decimals); | ||
await erc20Contract.connect(signer).approve(args.gatewayEvm, value); | ||
const method = | ||
"depositAndCall(address,uint256,address,bytes,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
value, | ||
args.erc20, | ||
encodedParameters, | ||
revertOptions, | ||
txOptions | ||
); | ||
} else { | ||
const value = utils.parseEther(args.amount); | ||
const method = | ||
"depositAndCall(address,bytes,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
encodedParameters, | ||
revertOptions, | ||
{ | ||
...txOptions, | ||
value, | ||
} | ||
); | ||
} | ||
|
||
return tx; | ||
}; |
Oops, something went wrong.