@coinbase/cdp-sdk 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +326 -28
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +8 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +2 -39
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/evm/transfer/utils.js +0 -12
- package/_cjs/actions/evm/transfer/utils.js.map +1 -1
- package/_cjs/actions/solana/constants.js +9 -0
- package/_cjs/actions/solana/constants.js.map +1 -0
- package/_cjs/actions/solana/transfer.js +117 -0
- package/_cjs/actions/solana/transfer.js.map +1 -0
- package/_cjs/actions/solana/utils.js +66 -0
- package/_cjs/actions/solana/utils.js.map +1 -0
- package/_cjs/analytics.js +70 -8
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +9 -3
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +133 -15
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/index.js +6 -0
- package/_cjs/client/policies/index.js.map +1 -0
- package/_cjs/client/policies/policies.js +232 -0
- package/_cjs/client/policies/policies.js.map +1 -0
- package/_cjs/client/policies/policies.types.js +3 -0
- package/_cjs/client/policies/policies.types.js.map +1 -0
- package/_cjs/client/solana/solana.js +76 -19
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +4 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +35 -4
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +56 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +2 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +14 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +42 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +6 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +245 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/policies/types.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +4 -2
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +8 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +2 -39
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/evm/transfer/utils.js +0 -11
- package/_esm/actions/evm/transfer/utils.js.map +1 -1
- package/_esm/actions/solana/constants.js +6 -0
- package/_esm/actions/solana/constants.js.map +1 -0
- package/_esm/actions/solana/transfer.js +114 -0
- package/_esm/actions/solana/transfer.js.map +1 -0
- package/_esm/actions/solana/utils.js +61 -0
- package/_esm/actions/solana/utils.js.map +1 -0
- package/_esm/analytics.js +70 -7
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +10 -4
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +133 -15
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/index.js +2 -0
- package/_esm/client/policies/index.js.map +1 -0
- package/_esm/client/policies/policies.js +228 -0
- package/_esm/client/policies/policies.js.map +1 -0
- package/_esm/client/policies/policies.types.js +2 -0
- package/_esm/client/policies/policies.types.js.map +1 -0
- package/_esm/client/solana/solana.js +76 -19
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +34 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +51 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +2 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +12 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +39 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +5 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +242 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/policies/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -3
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +6 -4
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +8 -54
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/transfer/utils.d.ts +0 -619
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +140 -68
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/constants.d.ts +6 -0
- package/_types/actions/solana/constants.d.ts.map +1 -0
- package/_types/actions/solana/transfer.d.ts +36 -0
- package/_types/actions/solana/transfer.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +27 -0
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +34 -0
- package/_types/actions/solana/utils.d.ts.map +1 -0
- package/_types/analytics.d.ts +14 -5
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +3 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +89 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +33 -3
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/index.d.ts +2 -0
- package/_types/client/policies/index.d.ts.map +1 -0
- package/_types/client/policies/policies.d.ts +216 -0
- package/_types/client/policies/policies.d.ts.map +1 -0
- package/_types/client/policies/policies.types.d.ts +96 -0
- package/_types/client/policies/policies.types.d.ts.map +1 -0
- package/_types/client/solana/solana.d.ts +43 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +14 -2
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +176 -17
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +3 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +2 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +18 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +1552 -0
- package/_types/policies/schema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +19 -0
- package/_types/policies/types.d.ts.map +1 -0
- package/_types/types/misc.d.ts +39 -0
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +11 -7
- package/accounts/evm/toEvmSmartAccount.ts +1 -2
- package/accounts/evm/types.ts +6 -8
- package/accounts/solana/toSolanaAccount.ts +8 -0
- package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
- package/actions/evm/transfer/transfer.ts +10 -51
- package/actions/evm/transfer/types.ts +9 -67
- package/actions/evm/transfer/utils.ts +0 -13
- package/actions/evm/types.ts +143 -78
- package/actions/solana/constants.ts +6 -0
- package/actions/solana/transfer.ts +219 -0
- package/actions/solana/types.ts +28 -0
- package/actions/solana/utils.ts +79 -0
- package/analytics.ts +86 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +159 -17
- package/client/evm/evm.types.ts +38 -1
- package/client/policies/index.ts +1 -0
- package/client/policies/policies.ts +246 -0
- package/client/policies/policies.types.ts +109 -0
- package/client/solana/solana.ts +94 -20
- package/client/solana/solana.types.ts +16 -1
- package/index.ts +7 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +220 -18
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +102 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +43 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -1
- package/openapi-client/generated/index.msw.ts +2 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +75 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +23 -0
- package/openapi-client/index.ts +6 -0
- package/package.json +4 -2
- package/policies/schema.ts +349 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
|
@@ -1,73 +1,40 @@
|
|
|
1
|
-
import { encodeFunctionData, erc20Abi
|
|
1
|
+
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
2
|
import { getErc20Address } from "./utils.js";
|
|
3
3
|
import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
|
|
4
4
|
export const accountTransferStrategy = {
|
|
5
5
|
executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
network,
|
|
14
|
-
});
|
|
15
|
-
return result.transactionHash;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const erc20Address = getErc20Address(token, network);
|
|
19
|
-
await apiClient.sendEvmTransaction(from.address, {
|
|
20
|
-
transaction: serializeEIP1559Transaction({
|
|
21
|
-
to: erc20Address,
|
|
22
|
-
data: encodeFunctionData({
|
|
23
|
-
abi: erc20Abi,
|
|
24
|
-
functionName: "approve",
|
|
25
|
-
args: [to, value],
|
|
26
|
-
}),
|
|
27
|
-
}),
|
|
28
|
-
network,
|
|
29
|
-
});
|
|
30
|
-
const result = await apiClient.sendEvmTransaction(from.address, {
|
|
31
|
-
transaction: serializeEIP1559Transaction({
|
|
32
|
-
to: erc20Address,
|
|
33
|
-
data: encodeFunctionData({
|
|
34
|
-
abi: erc20Abi,
|
|
35
|
-
functionName: "transfer",
|
|
36
|
-
args: [to, value],
|
|
37
|
-
}),
|
|
38
|
-
}),
|
|
39
|
-
network,
|
|
40
|
-
});
|
|
41
|
-
return result.transactionHash;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
return transactionHash;
|
|
45
|
-
},
|
|
46
|
-
waitForResult: async ({ publicClient, hash, waitOptions }) => {
|
|
47
|
-
let receipt;
|
|
48
|
-
try {
|
|
49
|
-
receipt = await publicClient.waitForTransactionReceipt({
|
|
50
|
-
hash,
|
|
51
|
-
pollingInterval: waitOptions?.intervalSeconds
|
|
52
|
-
? waitOptions.intervalSeconds * 1000
|
|
53
|
-
: undefined,
|
|
54
|
-
timeout: waitOptions?.timeoutSeconds ? waitOptions.timeoutSeconds * 1000 : undefined,
|
|
6
|
+
if (token === "eth") {
|
|
7
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
8
|
+
transaction: serializeEIP1559Transaction({
|
|
9
|
+
value,
|
|
10
|
+
to,
|
|
11
|
+
}),
|
|
12
|
+
network,
|
|
55
13
|
});
|
|
56
14
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
15
|
+
const erc20Address = getErc20Address(token, network);
|
|
16
|
+
await apiClient.sendEvmTransaction(from.address, {
|
|
17
|
+
transaction: serializeEIP1559Transaction({
|
|
18
|
+
to: erc20Address,
|
|
19
|
+
data: encodeFunctionData({
|
|
20
|
+
abi: erc20Abi,
|
|
21
|
+
functionName: "approve",
|
|
22
|
+
args: [to, value],
|
|
23
|
+
}),
|
|
24
|
+
}),
|
|
25
|
+
network,
|
|
26
|
+
});
|
|
27
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
28
|
+
transaction: serializeEIP1559Transaction({
|
|
29
|
+
to: erc20Address,
|
|
30
|
+
data: encodeFunctionData({
|
|
31
|
+
abi: erc20Abi,
|
|
32
|
+
functionName: "transfer",
|
|
33
|
+
args: [to, value],
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
network,
|
|
37
|
+
});
|
|
71
38
|
},
|
|
72
39
|
};
|
|
73
40
|
//# sourceMappingURL=accountTransferStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AAMrF,MAAM,CAAC,MAAM,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;QACxE,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAChD,WAAW,EAAE,2BAA2B,CAAC;oBACvC,KAAK;oBACL,EAAE;iBACH,CAAC;gBACF,OAAO;aACR,CAA+B,CAAC;QACnC,CAAC;QAED,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAC/C,WAAW,EAAE,2BAA2B,CAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,GAAG,EAAE,QAAQ;oBACb,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAChD,WAAW,EAAE,2BAA2B,CAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,GAAG,EAAE,QAAQ;oBACb,YAAY,EAAE,UAAU;oBACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAA+B,CAAC;IACnC,CAAC;CACF,CAAC"}
|
|
@@ -1,66 +1,49 @@
|
|
|
1
1
|
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
2
|
import { getErc20Address } from "./utils.js";
|
|
3
3
|
import { sendUserOperation } from "../sendUserOperation.js";
|
|
4
|
-
import { waitForUserOperation } from "../waitForUserOperation.js";
|
|
5
4
|
export const smartAccountTransferStrategy = {
|
|
6
5
|
executeTransfer: async ({ apiClient, from, to, value, token, network, paymasterUrl }) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return result.userOpHash;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const erc20Address = getErc20Address(token, network);
|
|
25
|
-
const result = await sendUserOperation(apiClient, {
|
|
26
|
-
smartAccount: from,
|
|
27
|
-
paymasterUrl,
|
|
28
|
-
network,
|
|
29
|
-
calls: [
|
|
30
|
-
{
|
|
31
|
-
to: erc20Address,
|
|
32
|
-
data: encodeFunctionData({
|
|
33
|
-
abi: erc20Abi,
|
|
34
|
-
functionName: "approve",
|
|
35
|
-
args: [to, value],
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
to: erc20Address,
|
|
40
|
-
data: encodeFunctionData({
|
|
41
|
-
abi: erc20Abi,
|
|
42
|
-
functionName: "transfer",
|
|
43
|
-
args: [to, value],
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
return result.userOpHash;
|
|
49
|
-
}
|
|
50
|
-
})();
|
|
51
|
-
return userOpHash;
|
|
52
|
-
},
|
|
53
|
-
waitForResult: async ({ apiClient, publicClient, from, hash, waitOptions }) => {
|
|
54
|
-
const result = await waitForUserOperation(apiClient, {
|
|
55
|
-
smartAccountAddress: from.address,
|
|
56
|
-
userOpHash: hash,
|
|
57
|
-
waitOptions,
|
|
58
|
-
});
|
|
59
|
-
if (result.status === "complete") {
|
|
60
|
-
return { status: "success", transactionHash: hash };
|
|
6
|
+
if (token === "eth") {
|
|
7
|
+
const result = await sendUserOperation(apiClient, {
|
|
8
|
+
smartAccount: from,
|
|
9
|
+
paymasterUrl,
|
|
10
|
+
network,
|
|
11
|
+
calls: [
|
|
12
|
+
{
|
|
13
|
+
to,
|
|
14
|
+
value,
|
|
15
|
+
data: "0x",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
61
20
|
}
|
|
62
21
|
else {
|
|
63
|
-
|
|
22
|
+
const erc20Address = getErc20Address(token, network);
|
|
23
|
+
const result = await sendUserOperation(apiClient, {
|
|
24
|
+
smartAccount: from,
|
|
25
|
+
paymasterUrl,
|
|
26
|
+
network,
|
|
27
|
+
calls: [
|
|
28
|
+
{
|
|
29
|
+
to: erc20Address,
|
|
30
|
+
data: encodeFunctionData({
|
|
31
|
+
abi: erc20Abi,
|
|
32
|
+
functionName: "approve",
|
|
33
|
+
args: [to, value],
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
to: erc20Address,
|
|
38
|
+
data: encodeFunctionData({
|
|
39
|
+
abi: erc20Abi,
|
|
40
|
+
functionName: "transfer",
|
|
41
|
+
args: [to, value],
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
64
47
|
}
|
|
65
48
|
},
|
|
66
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAK5D,MAAM,CAAC,MAAM,4BAA4B,GAA+C;IACtF,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE;QACtF,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE;gBAChD,YAAY,EAAE,IAAI;gBAClB,YAAY;gBACZ,OAAO;gBACP,KAAK,EAAE;oBACL;wBACE,EAAE;wBACF,KAAK;wBACL,IAAI,EAAE,IAAI;qBACX;iBACF;aACF,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAErD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE;gBAChD,YAAY,EAAE,IAAI;gBAClB,YAAY;gBACZ,OAAO;gBACP,KAAK,EAAE;oBACL;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,kBAAkB,CAAC;4BACvB,GAAG,EAAE,QAAQ;4BACb,YAAY,EAAE,SAAS;4BACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH;oBACD;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,kBAAkB,CAAC;4BACvB,GAAG,EAAE,QAAQ;4BACb,YAAY,EAAE,UAAU;4BACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH;iBACF;aACF,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { createPublicClient, http, erc20Abi, parseUnits } from "viem";
|
|
2
|
-
import { mapNetworkToChain } from "./utils.js";
|
|
3
1
|
/**
|
|
4
2
|
* Transfer an amount of a token from an account to another account.
|
|
5
3
|
*
|
|
@@ -10,51 +8,16 @@ import { mapNetworkToChain } from "./utils.js";
|
|
|
10
8
|
* @returns The result of the transfer.
|
|
11
9
|
*/
|
|
12
10
|
export async function transfer(apiClient, from, transferArgs, transferStrategy) {
|
|
13
|
-
const publicClient = createPublicClient({
|
|
14
|
-
chain: mapNetworkToChain(transferArgs.network),
|
|
15
|
-
transport: http(),
|
|
16
|
-
});
|
|
17
11
|
const to = typeof transferArgs.to === "string" ? transferArgs.to : transferArgs.to.address;
|
|
18
|
-
const value = await (async () => {
|
|
19
|
-
// user supplied a bigint. otherwise, we need to convert the amount to a bigint
|
|
20
|
-
if (typeof transferArgs.amount !== "string") {
|
|
21
|
-
return transferArgs.amount;
|
|
22
|
-
}
|
|
23
|
-
const decimals = await (async () => {
|
|
24
|
-
if (transferArgs.token === "eth") {
|
|
25
|
-
return 18;
|
|
26
|
-
}
|
|
27
|
-
else if (transferArgs.token === "usdc") {
|
|
28
|
-
return 6;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return publicClient.readContract({
|
|
32
|
-
address: transferArgs.token,
|
|
33
|
-
abi: erc20Abi,
|
|
34
|
-
functionName: "decimals",
|
|
35
|
-
args: [],
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
return parseUnits(transferArgs.amount, decimals);
|
|
40
|
-
})();
|
|
41
12
|
const transfer = {
|
|
42
13
|
apiClient,
|
|
43
14
|
from,
|
|
44
15
|
to,
|
|
45
|
-
value,
|
|
16
|
+
value: transferArgs.amount,
|
|
46
17
|
token: transferArgs.token,
|
|
47
18
|
network: transferArgs.network,
|
|
48
19
|
paymasterUrl: "paymasterUrl" in transferArgs ? transferArgs.paymasterUrl : undefined,
|
|
49
20
|
};
|
|
50
|
-
|
|
51
|
-
const result = await transferStrategy.waitForResult({
|
|
52
|
-
apiClient,
|
|
53
|
-
publicClient,
|
|
54
|
-
from,
|
|
55
|
-
hash,
|
|
56
|
-
waitOptions: transferArgs.waitOptions,
|
|
57
|
-
});
|
|
58
|
-
return result;
|
|
21
|
+
return transferStrategy.executeTransfer(transfer);
|
|
59
22
|
}
|
|
60
23
|
//# sourceMappingURL=transfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/transfer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/transfer.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,SAA+B,EAC/B,IAAO,EACP,YAAuF,EACvF,gBAA8C;IAE9C,MAAM,EAAE,GACN,OAAO,YAAY,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAE,YAAY,CAAC,EAAE,CAAC,OAAmB,CAAC;IAE/F,MAAM,QAAQ,GAAG;QACf,SAAS;QACT,IAAI;QACJ,EAAE;QACF,KAAK,EAAE,YAAY,CAAC,MAAM;QAC1B,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,YAAY,EAAE,cAAc,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;KACrF,CAAC;IAEF,OAAO,gBAAgB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { base, baseSepolia } from "viem/chains";
|
|
2
1
|
/**
|
|
3
2
|
* The address of an ERC20 token for a given network.
|
|
4
3
|
*/
|
|
@@ -22,14 +21,4 @@ const addressMap = {
|
|
|
22
21
|
export function getErc20Address(token, network) {
|
|
23
22
|
return addressMap[network][token] ?? token;
|
|
24
23
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Map a network to a viem chain.
|
|
27
|
-
* TODO: Add more networks (or dynamically map viem chains).
|
|
28
|
-
*
|
|
29
|
-
* @param network - The network to map to a chain.
|
|
30
|
-
* @returns The chain for the given network.
|
|
31
|
-
*/
|
|
32
|
-
export function mapNetworkToChain(network) {
|
|
33
|
-
return network === "base" ? base : baseSepolia;
|
|
34
|
-
}
|
|
35
24
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,GAAG;IACjB,IAAI,EAAE;QACJ,IAAI,EAAE,4CAA4C;KACnD;IACD,cAAc,EAAE;QACd,IAAI,EAAE,4CAA4C;KACnD;CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,OAAgB;IAC7D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const GENESIS_HASH_MAINNET = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
2
|
+
export const GENESIS_HASH_DEVNET = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
3
|
+
export const GENESIS_HASH_TESTNET = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
4
|
+
export const USDC_MAINNET_MINT_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
5
|
+
export const USDC_DEVNET_MINT_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../actions/solana/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,8CAA8C,CAAC;AACnF,MAAM,CAAC,MAAM,mBAAmB,GAAG,8CAA8C,CAAC;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,8CAA8C,CAAC;AAEnF,MAAM,CAAC,MAAM,yBAAyB,GAAG,8CAA8C,CAAC;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,8CAA8C,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getMint, getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, createTransferCheckedInstruction, } from "@solana/spl-token";
|
|
2
|
+
import { MessageV0, PublicKey, SystemProgram, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
|
|
3
|
+
import { getConnectedNetwork, getOrCreateConnection, getUsdcMintAddress, } from "./utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Transfers SOL or SPL tokens between accounts
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client to use
|
|
8
|
+
* @param options - The transfer options
|
|
9
|
+
*
|
|
10
|
+
* @returns The transfer result
|
|
11
|
+
*/
|
|
12
|
+
export async function transfer(apiClient, options) {
|
|
13
|
+
const connection = getOrCreateConnection({ networkOrConnection: options.network });
|
|
14
|
+
const tx = options.token === "sol"
|
|
15
|
+
? await getNativeTransfer({
|
|
16
|
+
connection,
|
|
17
|
+
from: options.from,
|
|
18
|
+
to: options.to,
|
|
19
|
+
amount: options.amount,
|
|
20
|
+
})
|
|
21
|
+
: await getSplTransfer({
|
|
22
|
+
connection,
|
|
23
|
+
from: options.from,
|
|
24
|
+
to: options.to,
|
|
25
|
+
mintAddress: options.token === "usdc"
|
|
26
|
+
? getUsdcMintAddress(await getConnectedNetwork(connection))
|
|
27
|
+
: options.token,
|
|
28
|
+
amount: options.amount,
|
|
29
|
+
});
|
|
30
|
+
const serializedTx = Buffer.from(tx.serialize()).toString("base64");
|
|
31
|
+
const signedTxResponse = await apiClient.signSolanaTransaction(options.from, {
|
|
32
|
+
transaction: serializedTx,
|
|
33
|
+
});
|
|
34
|
+
const decodedSignedTx = Buffer.from(signedTxResponse.signedTransaction, "base64");
|
|
35
|
+
const signature = await connection.sendRawTransaction(decodedSignedTx, {
|
|
36
|
+
skipPreflight: false,
|
|
37
|
+
maxRetries: 3,
|
|
38
|
+
});
|
|
39
|
+
return { signature };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the instructions for a native SOL transfer
|
|
43
|
+
*
|
|
44
|
+
* @param options - The options for the native SOL transfer
|
|
45
|
+
*
|
|
46
|
+
* @param options.connection - The Solana connection
|
|
47
|
+
* @param options.from - The source address
|
|
48
|
+
* @param options.to - The destination address
|
|
49
|
+
* @param options.amount - The amount to transfer
|
|
50
|
+
*
|
|
51
|
+
* @returns The native SOL transfer transaction
|
|
52
|
+
*/
|
|
53
|
+
async function getNativeTransfer({ connection, from, to, amount, }) {
|
|
54
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
55
|
+
const instructions = [
|
|
56
|
+
SystemProgram.transfer({
|
|
57
|
+
fromPubkey: new PublicKey(from),
|
|
58
|
+
toPubkey: new PublicKey(to),
|
|
59
|
+
lamports: amount,
|
|
60
|
+
}),
|
|
61
|
+
];
|
|
62
|
+
const messageV0 = new TransactionMessage({
|
|
63
|
+
payerKey: new PublicKey(from),
|
|
64
|
+
recentBlockhash: blockhash,
|
|
65
|
+
instructions,
|
|
66
|
+
}).compileToV0Message();
|
|
67
|
+
return new VersionedTransaction(messageV0);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the instructions for a SPL token transfer
|
|
71
|
+
*
|
|
72
|
+
* @param options - The options for the SPL token transfer
|
|
73
|
+
*
|
|
74
|
+
* @param options.connection - The Solana connection
|
|
75
|
+
* @param options.from - The source address
|
|
76
|
+
* @param options.to - The destination address
|
|
77
|
+
* @param options.mintAddress - The mint address of the token
|
|
78
|
+
* @param options.amount - The amount to transfer
|
|
79
|
+
*
|
|
80
|
+
* @returns The SPL token transfer transaction
|
|
81
|
+
*/
|
|
82
|
+
async function getSplTransfer({ connection, from, to, mintAddress, amount, }) {
|
|
83
|
+
const fromPubkey = new PublicKey(from);
|
|
84
|
+
const toPubkey = new PublicKey(to);
|
|
85
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
86
|
+
let mintInfo;
|
|
87
|
+
try {
|
|
88
|
+
mintInfo = await getMint(connection, mintPubkey);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`Failed to fetch mint info for mint address ${mintAddress}. Error: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
const sourceAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
94
|
+
const destinationAta = await getAssociatedTokenAddress(mintPubkey, toPubkey);
|
|
95
|
+
const instructions = [];
|
|
96
|
+
const sourceAccount = await getAccount(connection, sourceAta);
|
|
97
|
+
if (sourceAccount.amount < amount) {
|
|
98
|
+
throw new Error(`Insufficient token balance. Have ${sourceAccount.amount}, need ${amount}`);
|
|
99
|
+
}
|
|
100
|
+
// Check if destination account exists, if not create it
|
|
101
|
+
try {
|
|
102
|
+
await getAccount(connection, destinationAta);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, destinationAta, toPubkey, mintPubkey));
|
|
106
|
+
}
|
|
107
|
+
instructions.push(createTransferCheckedInstruction(sourceAta, mintPubkey, destinationAta, fromPubkey, amount, mintInfo.decimals));
|
|
108
|
+
return new VersionedTransaction(MessageV0.compile({
|
|
109
|
+
payerKey: fromPubkey,
|
|
110
|
+
instructions: instructions,
|
|
111
|
+
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../actions/solana/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,yBAAyB,EACzB,UAAU,EACV,uCAAuC,EACvC,gCAAgC,GACjC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,SAAS,EACT,SAAS,EACT,aAAa,EAEb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,E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connection to the Solana network
|
|
5
|
+
*
|
|
6
|
+
* @param options - The options for the connection
|
|
7
|
+
*
|
|
8
|
+
* @param options.networkOrConnection - The network to use or a connection
|
|
9
|
+
*
|
|
10
|
+
* @returns The connection
|
|
11
|
+
*/
|
|
12
|
+
export function getOrCreateConnection({ networkOrConnection, }) {
|
|
13
|
+
if (typeof networkOrConnection !== "string") {
|
|
14
|
+
return networkOrConnection;
|
|
15
|
+
}
|
|
16
|
+
return new Connection(networkOrConnection === "mainnet"
|
|
17
|
+
? "https://api.mainnet-beta.solana.com"
|
|
18
|
+
: networkOrConnection === "devnet"
|
|
19
|
+
? "https://api.devnet.solana.com"
|
|
20
|
+
: "https://api.testnet.solana.com");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the network of the connected Solana node
|
|
24
|
+
*
|
|
25
|
+
* @param connection - The connection to the Solana network
|
|
26
|
+
* @throws {Error} If the network is not mainnet, devnet, or testnet
|
|
27
|
+
*
|
|
28
|
+
* @returns The network of the connected Solana node
|
|
29
|
+
*/
|
|
30
|
+
export async function getConnectedNetwork(connection) {
|
|
31
|
+
const genesisHash = await connection.getGenesisHash();
|
|
32
|
+
if (genesisHash === GENESIS_HASH_MAINNET) {
|
|
33
|
+
return "mainnet";
|
|
34
|
+
}
|
|
35
|
+
else if (genesisHash === GENESIS_HASH_DEVNET) {
|
|
36
|
+
return "devnet";
|
|
37
|
+
}
|
|
38
|
+
else if (genesisHash === GENESIS_HASH_TESTNET) {
|
|
39
|
+
return "testnet";
|
|
40
|
+
}
|
|
41
|
+
throw new Error("Unknown network");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the USDC mint address for the given connection
|
|
45
|
+
*
|
|
46
|
+
* @param network - The network to use
|
|
47
|
+
*
|
|
48
|
+
* @returns The USDC mint address
|
|
49
|
+
*/
|
|
50
|
+
export function getUsdcMintAddress(network) {
|
|
51
|
+
if (network === "mainnet") {
|
|
52
|
+
return USDC_MAINNET_MINT_ADDRESS;
|
|
53
|
+
}
|
|
54
|
+
else if (network === "devnet") {
|
|
55
|
+
return USDC_DEVNET_MINT_ADDRESS;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error("Testnet is not supported for USDC");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../actions/solana/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAQxB;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,mBAAmB,GACU;IAC7B,IAAI,OAAO,mBAAmB,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,UAAU,CACnB,mBAAmB,KAAK,SAAS;QAC/B,CAAC,CAAC,qCAAqC;QACvC,CAAC,CAAC,mBAAmB,KAAK,QAAQ;YAChC,CAAC,CAAC,+BAA+B;YACjC,CAAC,CAAC,gCAAgC,CACvC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,UAAsB;IAC9D,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,cAAc,EAAE,CAAC;IAEtD,IAAI,WAAW,KAAK,oBAAoB,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,IAAI,WAAW,KAAK,mBAAmB,EAAE,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;SAAM,IAAI,WAAW,KAAK,oBAAoB,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,yBAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,wBAAwB,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
package/_esm/analytics.js
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import md5 from "md5";
|
|
2
|
+
import { APIError } from "./openapi-client/errors.js";
|
|
3
|
+
import { version } from "./version.js";
|
|
2
4
|
// This is a public client id for the analytics service
|
|
3
5
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
6
|
+
export const Analytics = {
|
|
7
|
+
identifier: "", // set in cdp.ts
|
|
8
|
+
wrapClassWithErrorTracking,
|
|
9
|
+
wrapObjectMethodsWithErrorTracking,
|
|
10
|
+
sendEvent,
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* Sends an analytics event to the default endpoint
|
|
6
14
|
*
|
|
7
15
|
* @param event - The event data containing event-specific fields
|
|
8
16
|
* @returns Promise that resolves when the event is sent
|
|
9
17
|
*/
|
|
10
|
-
|
|
18
|
+
async function sendEvent(event) {
|
|
19
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
11
22
|
const timestamp = Date.now();
|
|
12
23
|
const enhancedEvent = {
|
|
13
|
-
user_id:
|
|
24
|
+
user_id: Analytics.identifier,
|
|
14
25
|
event_type: event.name,
|
|
15
26
|
platform: "server",
|
|
16
27
|
timestamp,
|
|
17
28
|
event_properties: {
|
|
18
29
|
project_name: "cdp-sdk",
|
|
19
30
|
cdp_sdk_language: "typescript",
|
|
31
|
+
version,
|
|
20
32
|
...event,
|
|
21
33
|
},
|
|
22
34
|
};
|
|
@@ -45,10 +57,12 @@ export async function sendEvent(event) {
|
|
|
45
57
|
* Wraps all methods of a class with error tracking.
|
|
46
58
|
*
|
|
47
59
|
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
48
|
-
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
49
60
|
*/
|
|
50
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
-
|
|
62
|
+
function wrapClassWithErrorTracking(ClassToWrap) {
|
|
63
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
52
66
|
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
53
67
|
for (const method of methods) {
|
|
54
68
|
const originalMethod = ClassToWrap.prototype[method];
|
|
@@ -57,12 +71,11 @@ export function wrapClassWithErrorTracking(ClassToWrap, apiKeyId) {
|
|
|
57
71
|
return await originalMethod.apply(this, args);
|
|
58
72
|
}
|
|
59
73
|
catch (error) {
|
|
60
|
-
if (!(error
|
|
61
|
-
|
|
74
|
+
if (!shouldTrackError(error)) {
|
|
75
|
+
throw error;
|
|
62
76
|
}
|
|
63
77
|
const { message, stack } = error;
|
|
64
78
|
sendEvent({
|
|
65
|
-
apiKeyId,
|
|
66
79
|
method,
|
|
67
80
|
message,
|
|
68
81
|
stack,
|
|
@@ -75,4 +88,54 @@ export function wrapClassWithErrorTracking(ClassToWrap, apiKeyId) {
|
|
|
75
88
|
};
|
|
76
89
|
}
|
|
77
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Wraps all methods of an object with error tracking.
|
|
93
|
+
*
|
|
94
|
+
* @param object - The object whose methods should be wrapped.
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
function wrapObjectMethodsWithErrorTracking(object) {
|
|
98
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const methods = Object.getOwnPropertyNames(object).filter(name => name !== "constructor" && typeof object[name] === "function");
|
|
102
|
+
for (const method of methods) {
|
|
103
|
+
const originalMethod = object[method];
|
|
104
|
+
object[method] = async function (...args) {
|
|
105
|
+
try {
|
|
106
|
+
return await originalMethod.apply(this, args);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (!shouldTrackError(error)) {
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
const { message, stack } = error;
|
|
113
|
+
sendEvent({
|
|
114
|
+
method,
|
|
115
|
+
message,
|
|
116
|
+
stack,
|
|
117
|
+
name: "error",
|
|
118
|
+
}).catch(() => {
|
|
119
|
+
// ignore error
|
|
120
|
+
});
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Filters out non-errors and API errors
|
|
128
|
+
*
|
|
129
|
+
* @param error - The error to check.
|
|
130
|
+
* @returns True if the error should be tracked, false otherwise.
|
|
131
|
+
*/
|
|
132
|
+
function shouldTrackError(error) {
|
|
133
|
+
if (!(error instanceof Error)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (error instanceof APIError) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
78
141
|
//# sourceMappingURL=analytics.js.map
|