@automata-network/cctp-sdk
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
import { Signer } from 'ethers'; | ||
import { Signer, ethers } from 'ethers'; | ||
@@ -32,6 +32,6 @@ declare enum CCTPDomain { | ||
burnUSDC: (options: Omit<BurnUSDCOptions, "configsSet">) => any; | ||
getMessageBytes: (options: GetMessageBytesOptions) => { | ||
getMessageBytes: (options: GetMessageBytesOptions) => Promise<{ | ||
messageBytes: any; | ||
messageHash: string; | ||
}; | ||
}>; | ||
fetchAttestation: (options: Omit<FetchSignatureOptions, "configsSet">) => Promise<string>; | ||
@@ -45,6 +45,6 @@ mintUSDC: (options: Omit<MintUSDCOptions, "configsSet">) => any; | ||
burnUSDC: (options: Omit<BurnUSDCOptions, "configsSet">) => any; | ||
getMessageBytes: (options: GetMessageBytesOptions) => { | ||
getMessageBytes: (options: GetMessageBytesOptions) => Promise<{ | ||
messageBytes: any; | ||
messageHash: string; | ||
}; | ||
}>; | ||
fetchAttestation: (options: Omit<FetchSignatureOptions, "configsSet">) => Promise<string>; | ||
@@ -59,5 +59,10 @@ mintUSDC: (options: Omit<MintUSDCOptions, "configsSet">) => any; | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
destinationSigner?: Signer; | ||
onApprove?: () => void; | ||
onBurnUSDC?: () => void; | ||
onGetMessageBytes?: () => void; | ||
onFetchAttestation?: () => void; | ||
onMintUSDC?: () => void; | ||
beforeMintUSDC?: () => Promise<void>; | ||
@@ -67,3 +72,3 @@ } | ||
signer: Signer; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
sourceDomain: number; | ||
@@ -77,7 +82,8 @@ configsSet: CCTPSdkConfigsSet; | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
} | ||
interface GetMessageBytesOptions { | ||
approveTx: any; | ||
rpc: string; | ||
burnTxHash: string; | ||
} | ||
@@ -84,0 +90,0 @@ interface FetchSignatureOptions { |
@@ -1,2 +0,2 @@ | ||
import { Signer } from "ethers"; | ||
import { Signer, ethers } from "ethers"; | ||
export declare enum CCTPDomain { | ||
@@ -31,6 +31,6 @@ Ethereum = 0, | ||
burnUSDC: (options: Omit<BurnUSDCOptions, "configsSet">) => any; | ||
getMessageBytes: (options: GetMessageBytesOptions) => { | ||
getMessageBytes: (options: GetMessageBytesOptions) => Promise<{ | ||
messageBytes: any; | ||
messageHash: string; | ||
}; | ||
}>; | ||
fetchAttestation: (options: Omit<FetchSignatureOptions, "configsSet">) => Promise<string>; | ||
@@ -44,6 +44,6 @@ mintUSDC: (options: Omit<MintUSDCOptions, "configsSet">) => any; | ||
burnUSDC: (options: Omit<BurnUSDCOptions, "configsSet">) => any; | ||
getMessageBytes: (options: GetMessageBytesOptions) => { | ||
getMessageBytes: (options: GetMessageBytesOptions) => Promise<{ | ||
messageBytes: any; | ||
messageHash: string; | ||
}; | ||
}>; | ||
fetchAttestation: (options: Omit<FetchSignatureOptions, "configsSet">) => Promise<string>; | ||
@@ -58,5 +58,10 @@ mintUSDC: (options: Omit<MintUSDCOptions, "configsSet">) => any; | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
destinationSigner?: Signer; | ||
onApprove?: () => void; | ||
onBurnUSDC?: () => void; | ||
onGetMessageBytes?: () => void; | ||
onFetchAttestation?: () => void; | ||
onMintUSDC?: () => void; | ||
beforeMintUSDC?: () => Promise<void>; | ||
@@ -66,3 +71,3 @@ } | ||
signer: Signer; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
sourceDomain: number; | ||
@@ -76,7 +81,8 @@ configsSet: CCTPSdkConfigsSet; | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
} | ||
export interface GetMessageBytesOptions { | ||
approveTx: any; | ||
rpc: string; | ||
burnTxHash: string; | ||
} | ||
@@ -83,0 +89,0 @@ export interface FetchSignatureOptions { |
@@ -1,2 +0,2 @@ | ||
import { Contract, Signer } from "ethers"; | ||
import { Contract, Signer, providers } from "ethers"; | ||
import { Interface } from "ethers/lib/utils"; | ||
@@ -17,2 +17,6 @@ export declare function getUSDCContract(usdcContractAddress: string, signer: Signer): Contract; | ||
}): Promise<string>; | ||
export declare function getEthTransactionReceipt(options: { | ||
rpc: string; | ||
txHash: string; | ||
}): Promise<providers.TransactionReceipt>; | ||
export declare function parseLog(iface: Interface, logs: Array<any>, methodName: string): { | ||
@@ -19,0 +23,0 @@ log: any; |
{ | ||
"name": "@automata-network/cctp-sdk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "dist/index.mjs", | ||
@@ -23,3 +23,3 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"ethers": "^5.0.0", | ||
"ethers": "^5.6.8", | ||
"lodash": "^4.17.21" | ||
@@ -26,0 +26,0 @@ }, |
192
src/sdk.ts
@@ -1,4 +0,6 @@ | ||
import { Signer } from "ethers"; | ||
import { Signer, ethers } from "ethers"; | ||
import merge from "lodash/merge"; | ||
import { | ||
getEthTransactionReceipt, | ||
getMessageTransmitterContract, | ||
getTokenMessengerContract, | ||
@@ -41,4 +43,111 @@ getUSDCContract, | ||
const defaultConfigs: CCTPSdkConfigs = { | ||
testnet: {}, | ||
mainnet: {}, | ||
testnet: { | ||
irisApiHost: "https://iris-api-sandbox.circle.com", | ||
networks: [ | ||
{ | ||
domain: CCTPDomain.Ethereum, | ||
usdcContractAddress: "0x07865c6e87b9f70255377e024ace6630c1eaa37f", | ||
cctpMessageTransmitterContractAddress: | ||
"0x26413e8157cd32011e726065a5462e97dd4d03d9", | ||
cctpMessengerContractAddress: | ||
"0xd0c3da58f55358142b8d3e06c1c30c5c6114efe8", | ||
rpc: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", | ||
}, | ||
{ | ||
domain: CCTPDomain.Avalanche, | ||
usdcContractAddress: "0x5425890298aed601595a70ab815c96711a31bc65", | ||
cctpMessageTransmitterContractAddress: | ||
"0xa9fb1b3009dcb79e2fe346c16a604b8fa8ae0a79", | ||
cctpMessengerContractAddress: | ||
"0xeb08f243e5d3fcff26a9e38ae5520a669f4019d0", | ||
rpc: "https://rpc.ankr.com/avalanche_fuji", | ||
}, | ||
{ | ||
domain: CCTPDomain.Mumbai, | ||
usdcContractAddress: "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97", | ||
cctpMessageTransmitterContractAddress: | ||
"0xe09A679F56207EF33F5b9d8fb4499Ec00792eA73", | ||
cctpMessengerContractAddress: | ||
"0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5", | ||
rpc: "https://rpc.ankr.com/polygon_mumbai", | ||
}, | ||
{ | ||
domain: CCTPDomain.Optimism, | ||
usdcContractAddress: "0xe05606174bac4A6364B31bd0eCA4bf4dD368f8C6", | ||
cctpMessageTransmitterContractAddress: | ||
"0x9ff9a4da6f2157a9c82ce756f8fd7e0d75be8895", | ||
cctpMessengerContractAddress: | ||
"0x23a04d5935ed8bc8e3eb78db3541f0abfb001c6e", | ||
rpc: "https://goerli.optimism.io", | ||
}, | ||
{ | ||
domain: CCTPDomain.Arbitrum, | ||
usdcContractAddress: "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63", | ||
cctpMessageTransmitterContractAddress: | ||
"0x109bc137cb64eab7c0b1dddd1edf341467dc2d35", | ||
cctpMessengerContractAddress: | ||
"0x12dcfd3fe2e9eac2859fd1ed86d2ab8c5a2f9352", | ||
rpc: "https://goerli-rollup.arbitrum.io/rpc", | ||
}, | ||
{ | ||
domain: CCTPDomain.Base, | ||
usdcContractAddress: "0xf175520c52418dfe19c8098071a252da48cd1c19", | ||
cctpMessageTransmitterContractAddress: | ||
"0x9ff9a4da6f2157A9c82CE756f8fD7E0d75be8895", | ||
cctpMessengerContractAddress: | ||
"0x877b8e8c9e2383077809787ED6F279ce01CB4cc8", | ||
rpc: "https://goerli.base.org", | ||
}, | ||
], | ||
}, | ||
mainnet: { | ||
irisApiHost: "https://iris-api.circle.com", | ||
networks: [ | ||
{ | ||
domain: CCTPDomain.Ethereum, | ||
usdcContractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", | ||
cctpMessageTransmitterContractAddress: | ||
"0x0a992d191deec32afe36203ad87d7d289a738f81", | ||
cctpMessengerContractAddress: | ||
"0xbd3fa81b58ba92a82136038b25adec7066af3155", | ||
rpc: "https://rpc.ankr.com/eth", | ||
}, | ||
{ | ||
domain: CCTPDomain.Avalanche, | ||
usdcContractAddress: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", | ||
cctpMessageTransmitterContractAddress: | ||
"0x8186359af5f57fbb40c6b14a588d2a59c0c29880", | ||
cctpMessengerContractAddress: | ||
"0x6b25532e1060ce10cc3b0a99e5683b91bfde6982", | ||
rpc: "https://rpc.ankr.com/avalanche", | ||
}, | ||
{ | ||
domain: CCTPDomain.Optimism, | ||
usdcContractAddress: "0x0b2c639c533813f4aa9d7837caf62653d097ff85", | ||
cctpMessageTransmitterContractAddress: | ||
"0x4d41f22c5a0e5c74090899e5a8fb597a8842b3e8", | ||
cctpMessengerContractAddress: | ||
"0x2B4069517957735bE00ceE0fadAE88a26365528f", | ||
rpc: "https://rpc.ankr.com/optimism", | ||
}, | ||
{ | ||
domain: CCTPDomain.Arbitrum, | ||
usdcContractAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", | ||
cctpMessageTransmitterContractAddress: | ||
"0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca", | ||
cctpMessengerContractAddress: | ||
"0x19330d10D9Cc8751218eaf51E8885D058642E08A", | ||
rpc: "https://rpc.ankr.com/arbitrum", | ||
}, | ||
{ | ||
domain: CCTPDomain.Base, | ||
usdcContractAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", | ||
cctpMessageTransmitterContractAddress: | ||
"0xAD09780d193884d503182aD4588450C416D6F9D4", | ||
cctpMessengerContractAddress: | ||
"0x1682Ae6375C4E4A97e4B583BC394c861A46D8962", | ||
rpc: "https://mainnet.base.org", | ||
}, | ||
], | ||
}, | ||
}; | ||
@@ -100,5 +209,10 @@ | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
destinationSigner?: Signer; | ||
onApprove?: () => void; | ||
onBurnUSDC?: () => void; | ||
onGetMessageBytes?: () => void; | ||
onFetchAttestation?: () => void; | ||
onMintUSDC?: () => void; | ||
beforeMintUSDC?: () => Promise<void>; | ||
@@ -116,2 +230,7 @@ } | ||
destinationSigner, | ||
onApprove, | ||
onBurnUSDC, | ||
onGetMessageBytes, | ||
onFetchAttestation, | ||
onMintUSDC, | ||
beforeMintUSDC, | ||
@@ -126,2 +245,6 @@ } = options; | ||
if (onApprove) { | ||
onApprove(); | ||
} | ||
const approveTx = await approveUSDC({ | ||
@@ -134,7 +257,13 @@ signer, | ||
await waitForTransaction({ | ||
rpc: sourceNetworkConfigs.rpc, | ||
txHash: approveTx.hash, | ||
}); | ||
if (approveTx) { | ||
await waitForTransaction({ | ||
rpc: sourceNetworkConfigs.rpc, | ||
txHash: approveTx.hash, | ||
}); | ||
} | ||
if (onBurnUSDC) { | ||
onBurnUSDC(); | ||
} | ||
const burnTx = await burnUSDC({ | ||
@@ -154,4 +283,15 @@ signer, | ||
const { messageBytes, messageHash } = getMessageBytes({ approveTx }); | ||
if (onGetMessageBytes) { | ||
onGetMessageBytes(); | ||
} | ||
const { messageBytes, messageHash } = await getMessageBytes({ | ||
rpc: sourceNetworkConfigs.rpc, | ||
burnTxHash: burnTx.hash, | ||
}); | ||
if (onFetchAttestation) { | ||
onFetchAttestation(); | ||
} | ||
const attestationSignature = await fetchSignature({ | ||
@@ -166,2 +306,6 @@ configsSet, | ||
if (onMintUSDC) { | ||
onMintUSDC(); | ||
} | ||
const mintTx = await mintUSDC({ | ||
@@ -183,3 +327,3 @@ signer: destinationSigner || signer, | ||
signer: Signer; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
sourceDomain: number; | ||
@@ -193,4 +337,14 @@ configsSet: CCTPSdkConfigsSet; | ||
const contract = getUSDCContract(networkConfigs.usdcContractAddress, signer); | ||
const signerAddress = await signer.getAddress(); | ||
const allowance = await contract.allowance( | ||
signerAddress, | ||
networkConfigs.cctpMessengerContractAddress | ||
); | ||
return contract.approve(networkConfigs.cctpMessengerContractAddress, amount); | ||
if (allowance.lt(amount)) { | ||
return contract.approve( | ||
networkConfigs.cctpMessengerContractAddress, | ||
amount | ||
); | ||
} | ||
} | ||
@@ -203,3 +357,3 @@ | ||
destinationAddress: string; | ||
amount: number; | ||
amount: number | string | ethers.BigNumber; | ||
configsSet: CCTPSdkConfigsSet; | ||
@@ -237,9 +391,11 @@ } | ||
export interface GetMessageBytesOptions { | ||
approveTx: any; | ||
rpc: string; | ||
burnTxHash: string; | ||
} | ||
function getMessageBytes(options: GetMessageBytesOptions) { | ||
const { approveTx } = options; | ||
async function getMessageBytes(options: GetMessageBytesOptions) { | ||
const { rpc, burnTxHash } = options; | ||
const burnTx = await getEthTransactionReceipt({ rpc, txHash: burnTxHash }); | ||
const iface = new Interface(messageTransmitterAbi); | ||
const messageSentLogs = parseLog(iface, approveTx.logs, "MessageSent"); | ||
const messageSentLogs = parseLog(iface, burnTx.logs, "MessageSent"); | ||
const messageBytes = messageSentLogs?.parsedLog.args.message; | ||
@@ -286,3 +442,3 @@ const messageHash = keccak256(messageBytes); | ||
const networkConfigs = getNetworkConfigs(configsSet, destinationDomain); | ||
const contract = getTokenMessengerContract( | ||
const contract = getMessageTransmitterContract( | ||
networkConfigs.cctpMessageTransmitterContractAddress, | ||
@@ -292,3 +448,3 @@ signer | ||
return contract.mintUSDC(messageBytes, attestationSignature); | ||
return contract.receiveMessage(messageBytes, attestationSignature); | ||
} | ||
@@ -295,0 +451,0 @@ |
@@ -127,8 +127,4 @@ import { Contract, Signer, providers } from "ethers"; | ||
}) { | ||
const { rpc, txHash } = options; | ||
const receipt = await getEthTransactionReceipt(options); | ||
const provider = new providers.StaticJsonRpcProvider(rpc); | ||
const receipt = await provider.getTransactionReceipt(txHash); | ||
return receipt && receipt.status != null | ||
@@ -141,2 +137,14 @@ ? receipt.status === 0 | ||
export async function getEthTransactionReceipt(options: { | ||
rpc: string; | ||
txHash: string; | ||
}) { | ||
const { rpc, txHash } = options; | ||
const provider = new providers.StaticJsonRpcProvider(rpc); | ||
const receipt = await provider.getTransactionReceipt(txHash); | ||
return receipt; | ||
} | ||
export function parseLog( | ||
@@ -143,0 +151,0 @@ iface: Interface, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127041
2703
3
Updatedethers@^5.6.8